Building Conditional Logic Rules

Applying Conditional Logic adds intelligent automation to your mobile forms. You can use Conditional Logic to provide context for your field technicians, enhance their effectiveness, and enforce a workflow. This topic describes how to build and activate Conditional Logic rules.

Available on the Advanced and Enterprise tiers:

Essentials
Advanced
Enterprise

Contents

About

Conditional Logic uses “If This, Then That” statements to add intelligent automation into forms, guiding users of a form through a workflow depending on their context. Read more general information about Conditional Logic.

Create a Conditional Logic Rule

  1. Edit the form to open it in the Form BuilderClosed The Form Builder is the tool that form designers use to create forms. In the Form Builder, accessed from the TrueContext Web Portal, form designers can add and edit pages, sections, and questions, as well as attach data destinations and configure the form's settings..

  2. Select Conditional Logic > Add a Rule.

    Select "Add a Rule" in the Form Builder

  3. Enter a Rule Name that:

    • Is no more than 50 characters and is unique within the form.

    • Describes how the rule affects the form. A descriptive name makes it easy to find the rule in the side navigation when updating the Conditional Logic in the future.

  4. (Optional) Enter a Rule Description that provides a detailed summary of how the rule works and what it affects. A Rule Description can be up to 255 characters.

  5. (Optional) Switch off the rule for testing. The new rule is active by default. To test your form without the rule, switch Rule Active off.

    A Conditional Logic rule with Rule Active switched to the left position. This indicates the rule is inactive.

  6. Configure the If, Then, and Else statements as described below.

  7. Save the form.

Note: To make sure your Conditional Logic rules work as intended in the field, test them thoroughly before you deploy the form. Test the form under a variety of conditions to validate the field user experience.

"If" statements

This is the condition/set of conditions that must be met in order for any action to take place.

Every "If" Condition must contain the following: 

  1. Reference Question
  2. Operator
  3. Comparison Value or Question

If statement that shows the reference question "Is inspection required" with the operator "equals" and the comparison question value the constant "Yes"

Reference question

This is the question that you will be comparing. Only some types of questions are allowed to be used as a reference question. If you are using a Dropdown, Radio Button, Multiselect, Card List, or Button Group question with options "defined here", you can select those options from the IF dropdown.

The drop-down menu for selecting a reference question

Only questions with the following data types can be used as a reference question:

  • Freetext
  • URL/Email/Phone Number
  • Integer/Decimal/Currency
  • Duration
  • Date, Time, and Date/Time

The questions that are available to you will be restricted based on the above types. If the list is still large, begin typing a question identifier or question text to filter the list of available questions.

Info:If your team has the Multi-Language add-on, you can set up a condition based on the Selected Language. This is the language selected by the user, a dispatch, or an App‑to‑App call.

Operator

This is how you will be comparing the reference question with the comparison value or question.

The drop-down menu to select an operator

Possible operators include:

  • equals/does not equal

  • contains

  • is less than/is greater than

  • is less than or equal to/is greater than or equal to

  • is between

  • is/is not (for Selected Language conditions, Multi-Language add-on only)

  • matches/does not match a regular expression (regex)

    Info:Conditional Logic Regex Matching is available on the Enterprise tier only.

The operators that are available to you will be restricted based on the data type of the reference question you choose. For example, a "Freetext" data type cannot be "less than" anything. Review the list of what operators are valid for which question types and the full definitions for each operator.

Comparison value or question

This is the value (a constant or the answer to another question) to compare with the reference question.
The drop-down menu to select a comparison value or question

Compare to a constant

  • Simply type in the value you would like to compare it to, like "70" or "Pass."
  • The value must match the data type of the question.
  • For example, you cannot compare a question with an Integer data type to the word "Pass."

Compare to a question

  • Select a question from the list. The available questions will be limited to those with a matching data type. Optionally begin typing to filter the list of available questions.
  • If you are using a Dropdown, Radio Button, Multiselect, Card List, or Button Group question with options "defined here", you can select those options from the dropdown.

Compare to a language

(Multi-Language add-on only)

  • Select one or more languages from the list.

  • If you select more than one language, the condition is true if any of the languages match the Selected Language. You can also use the OR option if you want to define a separate condition for each language. Both ways of selecting more than one language have the same effect.

  • The list only includes the languages that are set up in the form settings.

Compare to a regular expression (regex)

(Enterprise tier only)

  • Enter a regular expression (regex) to match the answer against a pattern.

  • For example, you can set up a pattern to match:

    • Case-sensitive text

    • Ends with

    • Starts with

    • Wildcard characters (single and multiple)

Info:The topic Conditional Logic Regex Matching describes this feature in detail.

"If" Statements with Multiple Conditions

An If statement can contain multiple conditions, and you can specify whether ALL or ANY of the conditions must be true in order for the statement to be true and trigger the "Then" action.

To create an IF statement with multiple conditions:

  1. Choose AND if you want all conditions to be true in order for the actions to take place, or choose OR if you want any of them to be true in order for the actions to take place.

  2. A new block will appear underneath, separated by an AND or OR (whichever you chose). Configure the new condition.

"If" Statements with Sets of Conditions

It is also possible to build more complex statements that involve multiple conditions. For example, you could evaluate the following statement, where one simple condition could cause the "Then" actions to occur, or a set of two other conditions could trigger those actions:

If Total Inspection Score is less than 70 OR (Total Inspection Score is less than 80 AND Customer Satisfaction is less than 70)

Then Inspection Failed is not ignored

To create sets of conditions:

  1. Build an If statement with at least two conditions, as shown in the following example.

    If statement that shows two conditions: If "Is inspection requried?" = Yes AND if "Room being inspected" = Common Area

    Result: The Then action is triggered when an inspection is required and the room being inspected is the Common Area.

  2. Once you have at least two conditions defined, you can create different sets of conditions. To create a set of conditions, select the opposite “join” option.

    • If you select an option from within a condition, the Form Builder groups the selected condition with the new one:

      Brackets and shading indicate a set of conditions when you select, in this example, +OR within a condition (to the right of it)

    • If you select a join option outside a condition, the Form Builder groups the existing conditions into a set:

      If statement that shows the join options outside of any shaded and bracketed areas

      Result: The conditions joined by AND become a set of conditions:

      Set of conditions joined by AND indicated by brackets and shading, with the new OR condition shows as a separate bracket

  3. As you continue to add conditions, the Form Builder uses brackets and shading to show the structure of nested sets of conditions:

    Example "If" statement with nested OR conditions within an AND condition.

"Then" statements

"Then" is a list of actions; it controls what happens in the form when the "If" is true.

Every "Then" statement must contain the following: 

  1. An action target
  2. An action
  3. For some actions, a target value

Select "Then" statement actions

Action Target

This is the page, section or question that you would like to affect with Conditional Logic.

NOTE: Any action target (whether it is a page, section or question) must appear in the form AFTER every single question reference or comparison question that is in your "If" condition.

Select an action target for the "Then" statement

Action

This is what should happen to the action target -- what about it should be changed when the "If" is true. All action targets you use must come after ALL of the questions referenced in your "If" statement.

Select an action for the "Then" statement

  • Pages and sections:
    • Can be made ignored or not ignored.
  • Questions:
    • Can be made visible or not visible (any question type)
    • Can be reset or cleared (most question types)
    • Can be made required or not required (many question types)
    • Can be made read-only or not read-only (many question types)
    • Can be set to have a specific value (like "Pass" or "50") or be set to the value collected in another question (some question types)

The list of available actions will be filtered based on the type of action target (page, section, or type of question) that you chose. Review the full list of what actions are allowed, as well as the full definition of the actions.

Target Value

This field will only appear if you have selected "is set to" as the action. This is the value you would like your action target to be set to, if your "If" statement is true.

Select a target value for the "Then" statement

Set to a constant 

  • Simply type in the value you would like to set the question to, like "70" or "Pass."
  • The value must match the data type of the question. For example, you cannot compare a question with an Integer data type to the word "Pass."

Set to the answer of a question

  • Select a question from the list. Optionally, begin typing to filter the list of available questions 
    • The available questions will be limited to those with a matching data type.
    • The question must come BEFORE the action target in the form. 
  • If you are using a Dropdown, Radio Button, Multiselect, Card List, or Button Group question with options "defined here", you can select those options from the dropdown.

Set to the current date and time

(Enterprise tier only)

  • For a Date/Time Selector question, you can set the value to the current date and time.

  • This option does not apply to Date/Time Stamps.

Tip:If the answer to the Reference question changes, the rule runs again. When the If statement is true, the action updates the current date/time value. Field users might see the value change as they work through the form.

Then statement organization

Some Conditional Logic rules have multiple Then statements. If your rule has a long list of Then statements, organize the statements to run in a logical order. To move a Then statement, select the handle to the left of the statement and drag the row to a new place.

A list of Then statements in a Conditional Logic rule. Select the handle on to the left of a Then statement and drag it anywhere in the list.

You can also add a new Then statement anywhere in the list. Hover between two Then statements and select the plus sign [+] to add a new statement.

A list of Then statements in a Conditional Logic rule. Hover between two statements, and select the plus sign [+] to insert a statement.

Info:The topic Best Practices for Conditional Logic Rules describes the benefits of reordering Then statements in more detail.

"Else" statements

The "Else" statement contains a list of actions that should happen when your "If" statement is NOT true.

Every "Else" statement must contain the following: 

  1. An action target
  2. An action
  3. For some actions, a target value

"Else" statements are built in exactly the same way as "Then" statements.

Why build an "Else" statement?

"Else" statements are useful when mobile users make mistakes or change their mind. If they initially make a choice in the form that shows a page and makes a question required, but then change their mind, the "Else" statement needs to be able to hide the page and make the question not required.

In most cases the "Else" statement should simply do exactly the opposite of what your "Then" statement did.

Opposite Actions

Below is a list of actions that you might put in a "Then" statement, and their corresponding opposite actions that should be in the "Else."

"Then" Statement "Else" Statement
page is ignored is not ignored
section is ignored is not ignored
question is visible is not visible
question is set to is reset (or is cleared)
question is required is not required
question is read-only is not read-only

Auto-Generating "Else" Statements

If you only have one "If" statement in a Conditional Logic rule, the "Else" statements can be auto-generated. These will be the opposite actions (as listed in the table above) of the "Then" statement. If your Conditional Logic rule contains an "Else If" statement, the "Else" statements cannot be auto-generated.

Display for auto-generated "Else" statements

This functionality speeds up the creation of Conditional Logic rules. However, it can be disabled or overridden by selecting "Custom Actions":

Select custom actions for the "Else" statements

Tip:Else statements are optional—you can delete any or all of the actions. To delete an Else action, select Custom Actions, and then select the X next to the action.

"Else If" Statements

"Else If" statements are optional, and not needed for most conditions.

An "Else if" statement is an additional "If/Then" statement in the same Conditional Logic rule as another "If/Then". The "Else If" statement is only tested when the original If statement is NOT true.

A single Conditional Logic rule can have several "Else If" statements. If one statement evaluates as TRUE, the additional "Else if" statements following the TRUE statement will not be evaluated.

Example:

If the room being inspected equals the common room, then show the "common room" section, hide the "washroom" section, and hide the "warehouse" section.

Else If the room being inspected equals the washroom, then show the "washroom" section, hide the "common area" section, and hide the "warehouse" section.

Else If the room being inspected equals the warehouse, then show the "warehouse" section, hide the "common area" section, and hide the "washroom" section.

Else, hide the "common room" section, hide the "washroom" section, and hide the "warehouse" section. 

Why build an "Else If" statement?

"Else If" statements are especially useful if you are testing a question/group of questions where there are more than two mutually exclusive possible outcomes.

  • Sometimes, it is not possible to build separate Conditional Logic rules to accomplish this because they may conflict.
  • "Else If" statements help organize related but mutually exclusive Conditional Logic behavior under a single rule, making it easier to manage and modify the logic. 
  • If you have a lot of conditions like this, performance on mobile devices can be improved by using "Else if" statements to reduce the number of Conditional Logic rules. Try to put the scenario the form will launch in as the first "If" statement to improve performance more.

Testing and Troubleshooting

Note: To make sure your Conditional Logic rules work as intended in the field, test them thoroughly before you deploy the form. Test the form under a variety of conditions to validate the field user experience.

Conditional logicClosed Conditional logic is a tool in the Form Builder that establishes the workflow of a form. By using the "If This, Then That" structure, questions or sections will be displayed, hidden, or automatically populated based on answers to preceding questions. is very powerful and configurable, but it does introduce some complexity as well as more ways that things can go wrong. When you make changes, we highly recommend you test the following before deploying it to production, to ensure that everything behaves as expected:

  • Every condition and every possible path through the form.
  • What happens if you "undo" an answer that triggers Conditional Logic.
  • If you added a lot of new rules, test on the oldest/lowest memory mobile device that your field users may be using.
  • The order of Then statements in each rule. You can speed up troubleshooting during testing by keeping Then statements organized. This makes it easy to find and fix a problem if a rule doesn’t behave as expected.

You may want to deactivate Conditional Logic rules for testing purposes yet retain the rule configuration in the form.

To deactivate a Conditional Logic rule:

  1. Edit the form to open it in the Form Builder.

  2. Navigate to the Conditional Logic tab.

  3. Select the rule from the left navigation.

  4. Toggle Rule Active to the off position (left).

    List of conditional logic rules with an icon that shows "Brake Light Images" as inactive. This also shows the "Rule Active" toggle set to the off position (left).

Info:The icon next to the rule name in the left navigation indicates an inactive rule. The topic Viewing Form Details describes the Pages & Questions tab, which also indicates inactive rules.

To reactivate the rule, toggle Rule Active to the on position (right).