1. Home
  2. I am a Power/Promoted user
  3. Assessments/Forms
  4. Expressions for forms & business rules
  1. Home
  2. I am a Power/Promoted user
  3. Settings
  4. Expressions for forms & business rules

Expressions for forms & business rules

RESPONSUM has an expression engine with a set of expressions (comparable to functions in Excel) that can be used for:

  • Business rules (Settings >> Customization >> Business Rules): Allows you to hide fields in RESPONSUM Sub-modules based on values of other fields and expressions.
  • Form/Assessments (Settings >> Setup >> Form): Allows you to add logic to fields in a form (Questionnaire) to hide them, create calculations based on inputted values in fields etc.

Usable expressions

A full list of supported expressions can be found below with usage examples.

Key Notations:

[]: represents an empty list (some options should be selected first, and then unselected. If none was previously selected, the value will be undefined)

undefined: an option is not selected (yes-no question, multiple choice question)
Empty list and undefined values won’t work in expressions, but they represent certain states of inputs.

FunctionUsageResultExamples
Addadd(1; 2; 3; …)The sum of all numeric values found in the inputted items.– add(1; 2) = 3
– add(1; undefined; “foo”; 4) = 5
– add(1; “two”; [3, 4]) = 8
– add(-1; 1) = 0
– add(undefined; “text”; []) = undefined
Subtractsubtract(1; 2; 3; …)The first number in the inputted items subtracted by all other numeric values found. – subtract(1; 2) = -1
– subtract(1; undefined; “foo”; 4) = -3
– subtract(1; “text”; [3, 4]) = -6
– subtract(-1; 1) = -2
– subtract(undefined; “text”; []) = undefined
Multiplymultiply(1; 2; 3; …)The multiplication of all numeric values found.– multiply(1; 2) = 2
– multiply(1; undefined; “foo”; 4) = 4
– multiply(1; “two”; [3, 4]) = 12
– multiply(-1; 1) = -1
– multiply(undefined; “text”; []) = undefined
Dividedivide(1; 2; 3; …)The division of the first numeric value by the rest of the numeric values sequentially.– divide(1; 2) = 0.5
– divide(1; undefined; “text”; 4) = 0.25
– divide(1; “two”; [3, 4]) = 0.083333333333
– divide(-1; 1) = -1
– divide(undefined; “fish”; []) = undefined
– divide(1; 2; 3; 0) = undefined
Equalsequals(item1; item2)Returns a TRUE value if both inputted values are equal. Items are equal if they are the same type and value.

NOTE:
– Comparison is case-sensitive;
– Arrays (Ex. Multi select dropdowns) can be compared to other arrays;
– An empty array is considered equal to undefined;
– An array containing only 1 item is considered the single item/value it contains.
– equals(undefined; false) ⇒ false
– equals(”Cat”; “cat”) ⇒ false
– equals(”cat”; “cat” ⇒ true
– equals(true; 1) ⇒ false
– equals(false; false) ⇒ true
– equals([]; undefined) ⇒ true
– equals([]; “”) ⇒ false
– equals([”Sam”], [”Sam”]) ⇒ true
– equals ([”Sam”]; “Sam”) ⇒ true
– equals(”0”, 0) ⇒ false
Is Largerislarger(1; 2)Returns a TRUE value if 1 is larger than 2.

NOTE:
If the result is incomprehensible, we will return FALSE.
– isLarger(1;2) ⇒ false
– isLarger(2;1) ⇒ true
– isLarger(2;-1) ⇒ true
– isLarger(2;”one”) ⇒ false
– isLarger(2; 2) ⇒ false
– isLarger(2; undefined) ⇒ false
– isLarger(undefined; 2) ⇒ false
– isLarger(undefined; undefined) ⇒ false
Is Smallerissmaller(1; 2)Returns a TRUE value if 1 is smaller than 2.

NOTE:
If the result is incomprehensible, we will return FALSE.
– isSmaller(1;2) ⇒ true
– isSmaller(2;1) ⇒ false
– isSmaller(2;-1) ⇒ false
– isSmaller(2;”three”) ⇒ false
– isSmaller(2; 2) ⇒ false
– isSmaller(2; undefined) ⇒ false
– isSmaller(undefined; 2) ⇒ false
– isSmaller(undefined; undefined) ⇒ false
Is Larger Or Equalislargerorequal(1; 2)Returns a TRUE value if 1 is larger than OR equal to 2.

NOTE:
If the result is incomprehensible, we will return FALSE.
– isLargerOrEqual(1;2) ⇒ false
– isLargerOrEqual(2;1) ⇒ true
– isLargerOrEqual(2;-1) ⇒ true
– isLargerOrEqual(2;”one”) ⇒ false
– isLargerOrEqual(2; undefined) ⇒ false
– isLargerOrEqual(undefined; 2) ⇒ false
– isLargerOrEqual(undefined; undefined) ⇒ false
Is Smaller Or Equalissmallerorequal(1; 2)Returns a TRUE value if 1 is larger than or equal to 2.

NOTE:
If the result is incomprehensible, we will return FALSE.
– isSmallerOrEqual(1;2) ⇒ true
– isSmallerOrEqual(2;1) ⇒ false
– isSmallerOrEqual(2;-1) ⇒ false
– isSmallerOrEqual(2;”three”) ⇒ false
– isSmallerOrEqual(2; undefined) ⇒ false
– isSmallerOrEqual(undefined; 2) ⇒ false
– isSmallerOrEqual(undefined; undefined) ⇒ false
Concatenateconcatenate(item1; item2)Will add any found TEXT in the input values together. Also works with Arrays (Ex. Multiple choice fields with multiple selected values) of texts

NOTE:
Will ignore anything that is not a TEXT or arrays of text (such as numbers, yes/no values, etc)
– concatenate(“John”, [“Doe”, “is”], [“a”, “legend”], [“:-)”], undefined, [], 3, true) ⇒ “JohnDoeisalegend:-)”

Containscontains(item1; item2)Returns a TRUE value if the first inputted TEXT contains the second inputted TEXT.

NOTE:
– This expression is NOT case-sensitive
– Anything that is not “undefined” will be converted into TEXT before comparing it.
– contains(”foo”; “bar”) ⇒ false
– contains(”foo”;”o”) ⇒ true
– contains(undefined;undefined) ⇒ false
– contains(”5”, 5) ⇒ true
– contains(55, 5) ⇒ true
– contains (false, “false”) ⇒ true
– contains(”Sam”;”sam”) ⇒ true
Ifif(condition; item1; item2)If statement that allows you to input a condition first (Ex. Another expression). If the condition is TRUE, the first value is returned.
If the condition is FALSE, the second value is returned.
– if(true;1;2) ⇒ 1
– if(false;1;2) ⇒ 2
– if(undefined;1;2) ⇒ 2
– if(”flar”;1;2) ⇒ 2
Andand(conditon1; condition2; …)Returns a TRUE value if ALL conditions stated within return TRUE.– and(true; true) ⇒ true
– and(false; false) ⇒ false
– and(true; false) ⇒ false
– and(”foo”; “bar”) ⇒ undefined
– and(true; “flar”) ⇒ undefined
– and(”true”) ⇒ undefined
– and(1) ⇒ undefined
– and(undefined) ⇒ undefined
Oror(condition1; condition2; …)Returns a TRUE value if ANY conditions stated within returned TRUE.– or(true; true) ⇒ true
– or(false; false) ⇒ false
– or(true; false- ⇒ true
– or(”foo”; “bar”) ⇒ undefined
– or(true; “flar”) ⇒ undefined
– or(”true”) ⇒ undefined
– or(1) ⇒ undefined
– or(undefined) ⇒ undefined
Notnot(condition)Returns a TRUE value if the condition returns FALSE.– not(true) ⇒ false
– not(false) ⇒ true
– not(undefined) ⇒ undefined
– not(”flar”) ⇒ undefined
– not(1) ⇒ undefined
IsEmptyisempty(item)Returns a TRUE value if the item inputted is empty (Does not contain any values).

NOTE:
Works on TEXT and Arrays (ex. Multiple choice fields with multiple values selected).
– isEmpty(””) ⇒ true
– isEmpty([]) ⇒ true
– isEmpty(undefined) ⇒ true
– isEmpty([undefined; “”]) ⇒ true
– isEmpty(””;””;[];undefined;[undefined]) ⇒ true
– isEmpty(” “) ⇒ false
– isEmpty(”I am a mighty warrior!”) ⇒ false
– isEmpty(false) ⇒ false
– isEmpty(0) ⇒ false
Includesincludes(list; item)Returns a TRUE value if the item is equal to one of the items in the array.

NOTE:
– This expression is case sensitive and will look at IDs of options (not it’s labels)
– includes(multi-select; “option-id”)
– includes([”Option 1”]; [“Option 1”]) ⇒ true
– includes(false; false) ⇒ true
– includes(”Option 1”; “Option 2”) ⇒ false
– includes(”Option 1”; “option 1”) ⇒ false
Interpret Numbernum(item)Attempts to parse the inputted value as a number.

NOTE:
– Returns the default if it doesn’t work out;
– Always returns a number:
– true/false → 1 / 0
– text → will try to parse as number;
– Will return 0 if unparsable or empty
– undefined/null → empty
Example expression: add(num(<input>); 10)

Input and result:
– 3 => 13
– “3” => 13
– “” => 10
– ” ” => 10
– “/” => 10
– “a” => 10
– TRUE => 11
– FALSE => 10
Interpret Texttxt(item)Will return a TEXT representation of an inputted item.

NOTE:
– Fractional number → rounded to 2 digits after comma,
Boolean (true & false) → uses translations to return “Yes” (True) and “No” (False)
– undefined/null → returns empty text;
– Array (Ex. list of selected options) → will create a comma-separated list.
Example expression:
concatenate(txt(<input>); “_test”)

Input and result:
– 3 => 3_test
– 3.567 => 3.56_test
– true => yes_test
– false => no_test
– “” => _test
– [“Option 1”, “Option 2”, “Option 3”] => Option 1, Option 2, Option 3_test
Interpret Yes/Noyesno(item)Will return a Boolean (TRUE/FALSE) representation of an inputted item.

NOTE:
– Will interpret any number except 0 as “Yes”
– Will interpret else “No”
– “any-text” => false
– 3 -> true
– 0 -> false
– true -> true
– false -> false
– “yes” -> true
– “no” -> false
– “nope” -> false
– “yessir” -> false
Attributeattribute(relation_item; “attributeName”)Will fetch an “attribute” (Field) of an in RESPONSUM registered item in a sub-module. (Ex. The “Email” of a User Account)

NOTE:
– Also works with arrays (Ex. multiple choice of items). Will return an array of each object’s value.
– An object’s value can be an object again. (For example, I could use attribute(processing-activity, “owner”), which would return something of the type “user”. I could then say attribute(attribute(processing-activity, “owner”), “name”) to get the name of the owner of the processing activity.
– attribute(responsible_user; “name”) ⇒ “John”
– attribute(responsible_users; “email”) ⇒ [”john@responsum.eu”, “jeff@responsum.eu”]
Averageavg(items, more_items)Will calculate the average of a series of provided parameters. Disregards anything that is not a number.– avg(1) = 1 avg(1;2) = 1.5
– avg(1;2;undefined;undefined)=1.5
– avg(undefined;”fish”;true)=undefined
– avg(1;2;3;[1;2;3];undefined;”duckface”;-12)=0/7=0
Maximum (highest number)max(items, more_items)Will find the highest number in a series and skip over anything that is not a number.– max(1) = 1
– max(undefined) = undefined
– max(undefined;1) = 1
– max(1; 2; [3; 4];”text”;-6) = 4
Minimum (lowest number)min(items, more_items)Will find the lowest number in a series and skip over anything that is not a number.– min(1) = 1
– min(undefined;true;”text”) = undefined
– min(undefined;1) = 1
– min(1; 2; [3; 4];”text”;-6) = -6
Countcount(items, more_items)Will count items that are defined within the parameters.

This includes options selected in multiple choice questions and number of items in a repeatable section.
Useful for counting ex. the number of selected items in a dropdown, or the number of objects who have a certain attribute defined in a relation field (in combination with attribute)

– count(”my_option_field”) → 3 (assuming 3 options are selected in the field with the id “my_option_field”)
– count([50, 3]) → 2
– count(undefined) → 0 count([”foo”, undefined]) → 1
– count(50) → 1
– count(false) → 1
– count(1, 2, undefined, [3, 4, undefined], “two apples”) → 5
– count(section_id) → 1 (assuming a non-repeating section)
– count(repeating_section_id) → 3 (assuming the sections exists three times)
Roundingroundup(decimals, numbers) rounddown(decimals, numbers) round(decimals, numbers)Will round the number (up, down, or nearest), up to a number of decimals as specified in the first argument. Disregards anything that is not a number.Round up:
– roundup(0; 2) = 2
– roundup(0; 2.00001) = 3 roundup(0; [2.1; 3.1; 4]; 5; “text”; 99) = [3, 4, 4, 5, 99]
– roundup(0; ”text”) = undefined
– roundup(”text”, 1) = undefined
– roundup(2; 5,7777) = 5,78

Round down:
– rounddown(2; 5,7777) = 5,77

Round (Nearest):
– round(0; 5.1) = 5
– round(0; 5.6) = 6
Make a listflatlist(item_1, item_2, item_3)Will combine all input into a list.– flatlist(1; 2; 3;
– flatlist(4; 5;flatlist(6))) = [1, 2, 3, 4, 5, 6]
– flatlist(undefined; 1; “flar”) = [undefined, 1, “flar”]

As this can add major complexity to your forms/questionnaires, if you need any assistance, please reach out to us via support@responsum.eu.

We have consultants available to guide you through or take over this task fully so you get to the behavior you expect for your form/questionnaire.

Was this article helpful?

Related Articles