Arithmetic Functions

This post is referring to Vahana 2 (beta version). To check the document for production, please go to vDesigner-v1.0

In the Business Rule Manager module, you can use and apply arithmetic functions to perform basic and complex mathematical functions. These functions include Sum, Subtract, Product, Divide, Round, Truncate, and others. You can use arithmetic functions to implement the algorithm that performs an arithmetic calculation on a set of numbers.

The BRM (Business Rule Manager) module provides the following arithmetic functions:

Function NameFunction SyntaxDescription
AVGAVG(number1,number2,+)This function calculates the average of two or more numbers. In the AVG function, the number1 and number2 parameters specify numeric values.

The AVG function calculates the average of number1 and number2. When you use this function, you can configure the number1 and number2 parameters as follows:
1. Use the static function to enter the constant value of the parameters in the AVG function
2. Use the obj function, and then select the element if you want the AVG function to get the value of the parameters from the selected elements.

Also, you can click the plus sign to add more than two parameters.
SUMSUM(number1,number2,+)This function calculates the sum of two or more numbers. In the SUM function, the number1 and number2 parameters specify numeric values.

The SUM function calculates the sum (addition) of number1 and number2. When you use this function, you can configure the number1 and number2 parameters as follows:
1. Use the static function to enter the constant value of the parameters in the SUM function
2. Use the obj function, and then select the element if you want the SUM function to get the value of the parameters from the selected elements.

Also, you can click the plus sign to add more than two parameters.
PRODUCTPRODUCT(number1,number2,+)This function calculates the multiplication of two or more numbers. In the PRODUCT function, the number1 and number2 parameters specify numeric values.

The PRODUCT function performs the multiplication of number1 and number2. When you use this function, you can configure the number1 and number2 parameters as follows:
1. Use the static function to enter the constant value of the parameters in the PRODUCT function
2. Use the obj function, and then select the element if you want the PRODUCT function to get the value of the parameters from the selected elements.

Also, you can click the plus sign to add more than two parameters.
DivideDIVIDE(dividend,divisor)This function divides a number by any other number to get another number as a result. In this function, the dividend and divisor parameters specify numeric values. It divides the dividend by the divisor and gets a result.
PowerPOW(power,number)This function multiplies a number to the same number for a specific number of times. In this function, the power parameter specifies the number that is multiplied to itself. The number parameter specifies the exponent. The exponent means the number of times a number is multiplied to the same number.
FactorialFACTORIAL(number)This function multiplies a number by a number below it until it reaches one. In this function, the number parameter specifies a number that is multiplied by each number below it until it reaches one. 
MaximumMAX(numbers)This function returns the largest number from the list of multiple numbers.
MinimumMIN(numbers)This function returns the smallest number from the list of multiple numbers.
FloorFLOOR(number,significance)This function rounds a number down to the nearest greatest integer less than or equal to the current number. The FLOOR() function will typically round down accurately to the left.
RoundupROUNDUP(number,digits)This function rounds a number up to a given number of the decimal place. In the function, the number parameter specifies the number that the function rounds. The digits parameter specifies a given number of decimal places.
RandomRANDOM(lowerBound,upperBound,string)This function generates a random number from within the range of numbers. In the function, the lowerBound parameter specifies the smallest number in the range. The upperBound parameter specifies the largest number in the range.
RounddownROUNDDOWN(number,digits)This function rounds a number down to a given number of the decimal place. In the function, the number parameter specifies the number that the function rounds. The digits parameter specifies a given number of decimal places.
ModuloMOD(number,divisor)This function returns a remainder or signed remainder of a division after one number is divided by another number. In the function, the number parameter specifies the dividend, and the divisor parameter specifies the divisor.
LogLOG(number,base)This function returns the logarithm of a number. If the logarithm can not be calculated (for example, number or base is negative or zero), an exception is returned
CeilingCEILING(number,significance)This function returns the smallest integer that is greater than or equal to the specified number.
TruncateTRUNCATE(number)This function truncates the fraction of a floating point number. Truncating the fraction means that it removes the decimal part of the floating number and then returns a whole integer value. In the function, the number parameter specifies the floating number, which is truncated.
Format Number Localized Pattern
FORMATNUMBERLOCALIZEDPATTERN
(number,pattern,localeId)
This function formats a number according to the given locale and pattern. In the function:
1. The number parameter specifies the number that is formatted.
2. The pattern parameter specifies the pattern type. The number is formatted based on the pattern.
RoundROUND(number,digits)This function rounds a number to the next closest integer with the given precision.
RootROOT(root,number)This function returns the nth root of a number. In this function, the root parameter specifies the index or nth root. The second parameter, number, specifies the number. The function calculates and returns the root value of the number that you enter in place of the number parameter.
SubtractSUBTRACT(number1,number2)This function returns the difference after it substracts the second number from the first number. In the function, the number1 parameter specifies the first number. The number2 parameter specifies the second number, which is subtracted from the first number.
FindIndexFINDINDEX(list,BR)This function returns the index of the first element in a list. The first parameter, list, contains multiple numbers. The second parameter, BR, specifies the business rule that the function will execute to find the index of the first element.

To select a business rule, click the BR parameter, and a smart selector opens.

In the smart selector, you can select the business rule that you define in the Business Rule Manager module.

Example to Use Arithmetic Functions

Assume a user is implementing a functionality that performs the addition of two numbers. To make the functionality more interactive, the user has added three input fields and a push button. The application page appears as follows:

On clicking the Add button, a function must add two numeric values that an end-user enters in the First Number input field and Second Number input field. Thus, the application will display the sum of the first and second numbers in the Total input field. To implement this functionality, the user needs to perform the following activities:

  • Configure onClick event on the Add button
  • Configure Copy Data task on the onClick event
  • Implement Sum arithmetic function in the Copy Data task.

To implement the Sum function:

  1. On the vDesigner canvas, click the Add button, and the Button property panel comes into view.
  2. On the Button property panel, click the Events tab (), and the property panel displays the list of events.
  1. In the list of events, click the Add Config icon () to the right of the onClick event, and the Event Configuration page opens.
  2. On the Event Configuration page, in the Task panel, search and find the Copy Data task.
  1. After you find the Copy Data task, drag it to the Execution panel.
  1. In the Execution panel, the Copy Data task expands.
  2. Under Copy Data, in the Copy Data box, click the application tree icon (), and the Copy Data panel comes into view.
  1. In the Copy Data panel, click in the Copy From box, and a smart selector expands.
  1. In the smart selector, in the Search box, enter Sum and then find the Sum function.
  2. After you find the Sum function, select it, and the Copy From box starts displaying the Sum function.
  1. In the SUM function, you can configure the number1 and number2 parameters as follows:

Defining Constant Values in the Sum Function

You can define a constant value in a function when you do not want to take an input from the user and you want to display a pre-calculated value on the application page.

To define a constant value in the application:

  1. In the SUM function, click the number1 parameter, and a smart selector opens.
  2. In the smart selector, in the Search box, enter Static, and then find Static.
  3. After you find the Static function, select it, and the SUM function starts displaying the Static function.
  1. In the Static function, click the value parameter, and then enter the first number (for example:- 18) to perform the sum.
  1. Perform steps from step 1 to step 4 to replace the number2 parameter with another number.
  2. After you define the first and second numbers, the SUM function will add the first number to the second number.

Map Function’s Parameters to the elements

In a vDesigner function, you can map the function’s parameter to the element when you want to take an input from the user. In this case, a function will get the value from the related elements and then perform the related function.

To map the parameter to the element:

  1. In the SUM function, click the number1 parameter, and a smart selector opens.
  2. In the smart selector, in the Search box, enter Obj, and then find OBJ.
  3. After you find the OBJ function, select it, and the SUM function starts displaying the OBJ function.
  4. In the OBJ function, double-click the value parameter, and a smart selector expands.
  1. In the smart selector, select an element to map it to the Number1 parameter.
  2. Perform steps from step1 to step5 to map the Number2 parameter to another element.
  3. After you map the Number1 and Number2 parameters to different elements, the SUM function will get the values of the parameters from the mapped elements and add two numbers.

Managing the Resultant Value

After an arithmetic function generates the output, you can manage and manipulate the output in the following ways:

  • You can store the output in an entity
  • You can display the output on an application page

In these two cases, you can manage the output as follows:

  1. In the Copy Data panel, see the Copy To box.
  2. Click in the Copy To box, and a smart selector expands.
  3. In the smart selector, you can perform one of the following functions:

Case1:- (If you want to display the output in the element)

  1. In the smart selector, select the reference name of the element.

Case2:- (If you want to store the output in the entity)

  1. In the smart selector, select the entity’s name.
  2. After you select the element’s reference name or entity’s name, click Select to configure the arithmetic function.

Configuring Reload Elements Property

After you configure an arithmetic function on an event trigger, you need to mandatorily configure the Reload Elements property in the Copy Data task. Or, you can alternatively apply the Reload Elements task after you configure the Copy Data task to implement an arithmetic function.

If you do not apply the Reload Elements task or configure the Reload Elements property in the Copy Data task, the application will not display the group of elements on the application page after the configured arithmetic function completes its job.

Let’s discuss how to apply a Reload Elements task.

To configure the Reload Elements task:

  1. On the Event Configuration page, find the Task panel.
  2. In the Task panel, search and find the Reload Elements task.
  3. Drag the Reload Elements task from the Task panel to the Execution panel.
  4. Under Reload Elements, a group of boxes appears.
  5. In the boxes, configure different properties as follows:
ist/BoxDescriptionMandatory
Reference NameIn this box, enter the name of the task. Also, the system generates a reference name by default that you can change. Yes
Reload ElementsIn this box, you can configure the elements that the application will reload or redisplay after a configured arithmetic function completes its job.

To configure the elements:
a. In the Select Elements box, click the application tree icon (), and the right panel displays the Select Element area.
b. In the Select Element area, see the tree of different elements.



c. In the tree, click the right check box to select the related element that the application will reload.
d. Repeat step c to select other elements.
e. After you select elements, click Select to configure the elements for reloading.
No
  1. After you configure the related properties, click Save to configure the Reload Elements task.

Was this article helpful?
YesNo