Condition scripting

Condition scripting

Compose Enterprise is going through a design update. The illustrations on this page might be of the old design, but the information is up to date. Thank you for your patience during this update!

Norsk

To create a condition you will need to write short Groovy scripts in the scripting windows in Compose. Traditionally, you mainly create condition scripts in the script windows in the properties panel of condition- and multi condition activities in the Workflow Builder and in the Condition Builder for form elements in the Form Builder. The Condition Builder allows you to build conditions without scripting, but for more advanced conditions you will not be able to use the β€˜no-code’ interface.

Conditions have to evaluate to a Boolean value (true/false). If the condition is evaluated to being true, the action or consequence associated with it being true will occur. E.g. if you have a display condition, the element with the condition is hidden until the condition is fulfilled. Then the element will be displayed. If a condition fails to execute (because of script error) or returns a non-Boolean value, then the condition is false by default. Here is an overview of some of the operators and distinctions you can refer to when creating conditions in Compose.

Referring to different question types

Refer to different question answers, by using different code depending on the type of question:

Script

Description

Script

Description

Q1.answer

Refers to one answer from a value input question such as Input, Text Area and Date elements.

Q1.answer.value

Refers to one answer value from a single select question such as Radio button and Dropdown elements.

Q1.answers.value
Q1.answers.value[0]

Refers to a list of answer values from a multiselect question such as Check box elements. To refer to one answer value from the list, use []-syntax. Q1.answers.value[0] would for instance refer to the first answer value in the list, Q1.answers.value[1] to the second etc.

Operators

Here is an overview over the operators which can be used to set a condition.

Boolean operators

  1. && - AND operator

  2. || - OR operator

  3. ! - NEGATION operator

Comparison operators

  1. > - greater than

  2. < - less than

  3. == - equals

  4. >= - greater than or equals

  5. <= - less than or equals

Arithmetic operators

  1. + (addition)

  2. - (subtraction)

  3. * (multiplication)

  4. / (division)

Sample conditions

Questions validated as String

Scripts

Condition is true if …

Scripts

Condition is true if …

Q1.answer == "yes"

… the answer equals yes.

Q1.answer != "yes"

… the answer does not equal yes.

Q1.answer.startsWith("AA")

… the answer starts with the characters AA.

!Q1.answer.startsWith("AA")

… the answer does not start with the characters AA.

Q2.answer.value.contains("world")

… the answer contains the String world.

Questions validated as Integer/Decimal

Scripts

Condition is true if …

Scripts

Condition is true if …

Q1.answer > 100

… the answer is greater than 100.

Q1.answer < 200

… the answer is less than 200.

Q1.answer > 100 && Q1.answer < 200

… the answer is greater than 100 and less than 200.

Q1.answer == 100 || Q1.answer == 101

… the answer equals 100 or equals 101.

Q1.answer.value >= 201

… the answer is equal or greater than 201.

(((Q1.answer + Q4.answer) * Q3.answer ) / Q6.answer ) < 123

… the arithmetically calculated answer is less than 123.

Questions validated as Date

Scripts

Condition is true if …

Scripts

Condition is true if …

Q1.answer.after("2020-01-01")

… the answer date is after 1st of January 2020.

Q1.answer.before("2020-01-01")

… the answer date is before 1st of January 2020.

Q1.answer.year == 2020

… the answer year equals 2020.

Q1.answer.month != 3

… the answer month does not equal March.

Q1.answer.day == 1

… the answer day equals the 1st.

Β