Calculate

Prev Next

See also: Calculation field

The Behavior type Calculate executes a Calculation expression that can be used in many ways to evaluate data available in the context of a form or to extract new data from it.

The optional check expression influences whether the actions are executed on 'true' or 'false' by returning a value that can be interpreted as a truthy/falsy value. The input value $input is the output value of the expression above. However, the variable 'orgInput' can also be used to access the original input value of the behavior ($var(orgInput)).

images/download/attachments/177913913/image-2024-9-25_15-53-57-version-1-modificationdate-1727272436828-api-v2.png

The Behavior type Calculate executes a Calculation expression that can be used in many ways to evaluate data available in the context of a form or to extract new data from it.

The return value of the 'calculation' overwrites the original input data ($input) of the behavior. However, the Calculation expression can refer to input data (e.g. by $input) provided by a Events (Form designer) (e.g. Changed) or from a calling behavior (see Execute behaviour). The rest of the procedure depends partly on whether an optional Check expression has been configured to determine a Boolean value by another Calculation expression for the selection of the actions (on 'true'/'false') to execute.

Overall, the following cases must be differentiated:

  • If the Calculation expression contains syntactical errors (e.g. regarding the use of parentheses), the Actions on "false" will be executed. An error message is assigned as input data ($input). Any Check expression that has been defined is then not evaluated. The original input value of the behavior can be accessed via the orgInput variable ($var(orgInput))

  • If no Check expression is defined, then the return value from a syntactically correct Calculation expression ($input) is passed to the Actions on "true". This is also the case if the return value is empty ($null), which happens, for example, with a 'division by 0'.

  • If a Check expression is defined, it is evaluated as a Calculation expression whereby the return value from the already evaluated Calculation expression provides the input data ($input).

    • If the Check expression contains syntactical errors (e.g. regarding the use of parentheses), the Actions on "false" will be executed. An error message is assigned as input data ($input).

    • If the result of the Check expression is not considered false according to the following table, the input data ($input) from the Calculation expression is passed to the Actions on "true".

    • If the result of the Check expression is interpreted as false according to the following table, the input data ($input) from the Calculation expression is passed to the Actions on "false".

      Data type

      Values that are considered false ('falsy'):

      (none)

      null ($null)

      Boolean value

      false

      Number

      0

      Text

      '', '0', 'false', 'no' (not case sensitive)

Example

A numeric input field (for integers) should determine and display whether the assigned numeric value is even or odd, each time the value is changed.

images/download/attachments/177913913/image2020-5-8_16-10-18-version-1-modificationdate-1727270243352-api-v2.png

images/download/attachments/177913913/image2020-5-8_16-10-42-version-1-modificationdate-1727270243347-api-v2.png

Configuration:

images/download/attachments/177913913/image-2024-9-26_9-19-27-version-1-modificationdate-1727335166541-api-v2.png

  • A behavior with the Behavior type Calculate is set up for the input field, which responds to the trigger Changed (not shown in screenshot) with all change types.


  • The Calculation expression calc (Calculate expression) determines the remainder of an integer division of the input value ($input) by 2 ('modulo 2', see Calculate value). For even numbers, this expression returns the value 0, for odd numbers it returns 1.


  • The Check expression uses the cmp (Compare) function to convert the result returned ($input) by the Calculation expression into a Boolean value:

    • If $input = 0, $cmp will return 'true' and the Actions on "true" are relevant.

    • Otherwise $cmp returns 'false' and the Actions on "false" are relevant.


  • Under Actions on "true", the action Set hint sets the text to 'even number' for the Target element.


  • Under Actions on "false", the action Set hint sets the text to 'odd number' for the Target element.

â–ºNOTEâ—„ Since the number 0 in the Check expression is interpreted as 'false' (see table above), it could be assumed that in this example the Check expression $not($input)would give the same results as $cmp($input,=,0). But this is not the case, because for the function not (Logical negation), every value that is not matching 'true' (case-insensitive) is considered 'false'. However, assigning $input directly as a Check expression and swapping the two Set hint actions would yield appropriate results.