In addition to fields and rules, calculations comprise the entity's data structure. Calculations are a special type of rule that are "always on". Whenever other fields, calculations, or rules that the calculation is dependent on change, the rule engine will recalculate the calculation rule's value.
Use calculations to create values that are the result of arithmetic operations, expressions, conditional statements, function calls, etc. InRule features a spreadsheet-like syntax for creating the logic, conditions, and expressions used for calculations and rules. Once created, your applications can leverage these potentially complex calculations by name for display or use within other processes.
Calculations are most appropriate when there is a benefit to referencing a given expression in multiple places or when you want to define a value in output state via a single expression, and when the rule expression is relatively simple.
Adding a calculation
Right-click on the element to which you want to add to. Select Add -> Calculation
Deleting a calculation
There are a few ways to do this:
- Right-click on the calculation you wish to delete, and select Delete.
- Click on the calculation you wish to delete and click Delete on the Home Banner.
- Click on the calculation you wish to delete and hit the Delete key on your keyboard.
You will be prompted to confirm the deletion. Click Yes.
Specifies the name of the calculation.
Specifies the name that will be used in the business language editor when referring to this field.
Specifies the data type of the field. The available options are:
Specifies the expression that will be evaluated when rules and calculations are run.
Clicking on the button will display the Expression editor.
Clicking on the button will switch between InRule syntax and business language syntax.
Clicking on the hyperlink will navigate to the Vocabulary folder for the entity in which this calculation is contained. Any calculation may have one or more classifications associated with it, such as a “Young” classification for an “Age” field meaning < 30 years.
Any calculation may have one or more Constraints associated with it, which will automatically be enforced for any data that is set for the calculation. When a Constraint is violated, InRule triggers a validation message containing information about the field and Constraint that is in violation. Clicking on the Constraint hyperlink will navigate to the Constraints for the entity in which this calculation is contained.
Functions are predefined calculations that use specific values, called arguments, in a particular order, or structure. Functions can be used to perform simple or complex calculations.
Structure of a function
The structure of a function begins with the function name, an opening parenthesis, the arguments for the function separated by commas, and a closing parenthesis.
For a list of available functions, click on the expression builder button on the right of the calculation text box.
Arguments can be numbers, text, logical values such as TRUE or FALSE, collections, calculations, fields, constants, expressions, or other functions.
Expressions are equations that perform calculations on values in your rule application. For example, the following formula multiplies 4 by 5 and then adds 6 to the result.
An expression can also contain any or all of the following: functions, references to other fields and calculations, operators, and constants. You can use parentheses to control the order in which an expression is evaluated.
The following is an example of an expression and the breakdown of its components:
- Functions: The Round() function specifies the number of digits to the right of the decimal point to truncate
- References: Invoice. Total the value of the Total calculation on the Invoice entity.
- Operators: The "+" (or plus) operator adds the constant 20 to the result of the round function.
- Constants: Numbers or text values entered directly into a formula, such as 20.
Operators specify the type of calculation that you want to perform on the elements of a calculation. InRule includes three different types of calculation operators: arithmetic, comparison, and text.
Type of operators
InRule supports the following arithmetic operators to perform basic mathematical operations such as addition, subtraction, or multiplication:
\ (integer division)
You can compare two values with the following operators. When two values are compared by using these operators, the result is a logical value either TRUE or FALSE.
> (greater than)
< (less than)
>= (greater than or equal to)
<= (less than or equal to)
<> (not equal to)
Please review the Value Comparison topic for additional detail about value comparison in InRule.
You can combine logical conditions into larger conditions by using logical operators.
a And b
a Or b
a Xor b
Not(a or b)
Text concatenation operator
Use the ampersand (&) to join, or concatenate, one or more text strings to produce a single piece of text.
Order of operation
If you combine several operators in a single calculation, InRule performs the operations in the order shown in the following list. As a default, InRule evaluates the operators from left to right.
* and / (Multiplication and division)
+ and – (Addition and subtraction)
= < > <= >= <> (Comparison)
Use of parentheses
To change the order of evaluation, enclose in parentheses the part of the calculation to be calculated first.
For example, the following formula produces 11 because InRule calculates multiplication before addition. The calculation multiplies 2 by 3 and then adds 5 to the result.
In contrast, if you use parentheses to change the syntax, InRule adds 5 and 2 together and then multiplies the result by 3 to produce 21.