Expression

The Expression question type in an assessment template allows you to write an expression to define conditions for showing a specific text based on responses or parameters assigned to questions. The expression evaluates the conditions you define and determines which text to show. For example, you can write an expression to assign risk levels based on the total scores and determine the risk level text to show.

Using an expression, you can dynamically evaluate and present information based on the values obtained from specific questions, allowing for customized text to be shown.

Note 
  • When writing an expression, use IDs instead of display names. For example, if the display name of a text box type of question is Explain and its ID is question1, use question1 in the expression.
    Image of a text box and its properties
  • Similarly, if the display text of a checkbox type of question is Yes and its value is Item 1, use Item 1 in the expression.
    Image of a checkbox and its properties
Example 

This example shows how to use an Expression question type to assign risk levels based on the total scores obtained from Yes/No questions in a template. The expression used in the example uses an immediate if (iif) function to determine the risk level.

Suppose that your template contains the following questions:

  • A Yes/No question whose ID is Q1 and score is 5.
  • A Yes/No question whose ID is Q2 and score is 10.

You want to assign the risk level based on the sum of the scores of Q1 and Q2, as follows:

  • If the total score is greater than 10, show High Risk.
  • Otherwise, if the total score is greater than 5, show Medium Risk.
  • Otherwise, show Low Risk.

Then, you can use the Expression question type to provide the following expression:

iif({totalScore} > 10, 'High Risk', iif({totalScore} > 5, 'Medium Risk', 'Low Risk'))

The outer iif function checks if the total score is greater than 10. If true, it returns High Risk. If false, it evaluates the second iif function.

The second iif function checks if the total score is greater than 5. If true, it returns Medium Risk. If false, it returns Low Risk.

Image of the Template Designer tab with the Expression section

Depending on the combination of responses to questions Q1 and Q2, the Expression question, which is named Risk in this example, shows the corresponding risk level text.

  • If Q1 and Q2 have the value Yes, the total score becomes 15. Therefore, the Risk field shows the value High Risk.
  • If Q1 has the value Yes and Q2 has the value No, the total score becomes 5. Therefore, the Risk field shows the value Low Risk.
  • If Q1 has the value No and Q2 has the value Yes, the total score becomes 10. Therefore, the Risk field shows the value Medium Risk.
  • If Q1 and Q2 have the value No, the total score becomes 0. Therefore, the Risk field shows the value Low Risk.

Image of the Test Template tab

Example 

This example shows how to use an Expression question type to assign action levels based on the responses to specific questions in a template. The expression used in the example uses an immediate if (iif) function to determine the action level.

Suppose that your template contains the following questions:

  • A text box whose ID is Q1.
  • A checkbox whose ID is Q2.
    • The value of the Yes text in the checkbox is Item 2.

You want to assign the action level based on the responses to Q1 and Q1, as follows:

  • If Q1 contains biometric or social and if Q2 is Yes, show Action Needed.
  • Otherwise, show No Action Needed.

Then, you can use the Expression question type to enter the following expression:

iif(({q1} contains 'biometric' or {q1} contains 'social') and {q2} contains 'item 2', 'Action Needed', 'No Action Needed')

The iif function checks if Q1 contains "biometric" or "social" and if Q2 is "Yes". If true, it returns Action Needed. If false, it returns No Action Needed.

Image of the Template Designer tab with the Expression section

Depending on the combination of responses to questions Q1 and Q2, the Expression question, which is named Action in this example, shows the corresponding action level text.

Image of the Test Template tab