Calculate

See also: Calculation field

The Behaviour 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 behaviour ($var(orgInput)).


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

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 behaviour with the Behaviour 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.