- Evaluating a Single Logic Rule
- Evaluating your Conditional Logic as a Whole
- Else: What happens when users change their mind?
- Ignored vs Not Visible: What's the Difference?
- Dispatching into Forms with Conditional Logic
Note: V2 Forms are available to all customers. If you do not have access to the V2 Form Builder and Forms, please read: Enabling V2 Forms
While conditional logic in forms simplifies mobile users' workflow, as you build more complex conditional logic into forms there are more opportunities to make mistakes in building it. This article is a best practices guide and will discuss a number of potential pitfalls when building conditional logic forms.
Conditional logic can only be used with V2 forms.
The Form Builder prevents most errors that are contained within a single conditional logic rule. In most simple cases, the Form Builder will only let you deploy the form if the rule is valid.
Errors that will prevent you from saving a form:
In your IF Statement...
- You have an incompatible reference question/operator combination
- You are comparing a reference question to an incompatible constant or question
- A question referenced is not in a valid part of the form for comparison (it is inside of a repeatable section, and the conditional logic is written at the form level)
In your THEN Statement...
- You are performing an action that is invalid for the action target (the page, section or question that you are acting on)
- You are setting a question to an invalid constant or data type
- The action target does NOT appear in the form after all the elements in your "If"
- The action target is in an area of the form that is not valid to be acted on (it is inside of a repeatable section, and the conditional logic is written at the form-level, rather than within the repeatable section
Errors that you must check for:
The Form Builder is currently unable to check for these issues.
- Elements of your IF statement contradict each other
- I.e. You have not set up the rule so that it can never be true
- IF Q1 = 5 AND Q1 = 8
- Elements of your THEN statement contradict each other
- I.e. You have set up the rule so that it is impossible for the action occur
- THEN Q1 is visible AND Q1 is not visible
The Form Builder validates that each individual rule is valid, but it does not validate conditional logic rules against one another. As you are building more complex conditional logic into a form, there are a number of things to watch out for.
When you have many conditional logic rules, the easiest way to get an overview of them is in the Web Portal. See here for more information.
Conflicting Conditional Logic Rules
Watch out for conditional logic rules that overwrite the action of another rule.
THEN Q3 is Visible
ELSE Q3 is Not Visible
THEN Q3 is Not Visible
ELSE Q3 is Visible
In the example above, while each rule is perfectly valid on its own, Q3 will have strange behaviour. If Q1 does equal 5, and Q2 is indeed less than 3, the visibility of Q3 will depend on which question the mobile user last interacted with -- so if they last modified Q1 that is the rule that will control the behaviour.
It would be best to rewrite this as a single rule:
IF Q1 !=5 AND Q2 <3
THEN Q3 is Not Visible
ELSE Q3 is Visible
When building conditional logic, remember that conditional logic is not the only thing acting on a form -- your field users are as well! Remember that the behaviour of mobile users will always have more of an impact on the outcome of a form than conditional logic does.
Users overwriting your conditional logic outcomes
Imagine you have a form with the rule below.
THEN Q3 is set to "Fail"
ELSE Q3 is set to "Pass"
After using the form successfully in the field for a while with no issues, you receive a form submission where Q1 had the answer of 30 (a very failed inspection), yet Q3 is marked as "Pass."
- First, check your conditional logic
- If there are no rules that would have overwritten this, it's highly likely that the mobile user manually changed the answer of Q3.
If you are conditionally setting the values of a question, it's best to make sure that question is also Read-Only (conditionally or not) -- unless you are okay with users making manual changes to it.
As conditional logic affects the workflow a user sees, it is important to think about what happens when a user goes back and changes an answer. This section will discuss best practices to avoid confusion or showing unnecessary information based on answers being changed.
ELSE Actions must include undoing all IF Actions
When building conditional logic workflows it is important to keep in mind what happens when an answer is changed, and build appropriate actions into all ELSE conditions. Using our room inspection example:
- If the room gets a score of less than 50, the inspection has failed. Users will then see a Required Comments section, and see Page 2, which contains questions for failed inspections.
- If the room gets a score of above 50, the inspection passes and the Required Comments section is not shown/available, nor is Page 2.
|"Good" ELSE||If Q1 <50
This "ELSE" defines what to do if Q1 is not <50. This causes the following sequence:
|"Bad" ELSE|| If Q1 <50
This "ELSE" condition only works on the first encounter with the question. The sequence would be:
Pages and Sections can be ignored, while Questions can be made visible/not visible. Read more about the available actions in conditional logic here. Understanding this concept is important if you are building complex forms.
- Data in "Ignored" parts of the form does not exist as far as the form is concerned
- It will not be visible to mobile users
- It will not push information to subsequent fields in the form
- It will not be used in calculations, filters, etc in subsequent fields in the form
- It will be considered empty if referenced in conditional logic rules
- It will not be submitted to the web portal so that it can be reviewed in results
- Therefore, "Ignoring" a page can cause major downstream impacts in a form.
- Data in "Not Visible" question does exist as far as the form is concerned
- Mobile users will not see it, but...
- It can still push information to other questions
- It will be used in calculations, filters, etc in subsequent fields of the form
- It's value will be used if it is referenced in conditional logic rules
- It will be submitted to the web portal
- Therefore, the action of making a question "Not Visible" doesn't affect the downstream flow of the form as much, but the data in it does still affect the form.
What if I want to "Ignore" a question?
If you want a question to be conditionally not visible to users, and you don't want to keep the data in it when it is hidden, here are your options.
- Place the question in a section that you will "Ignore" instead
- Or, the conditional logic rule that sets the question to "Not Visible" should also "Reset" the Question at the same time.
What if I want a Page or Section to be Not Visible, but I want to use the data in it?
This isn't really possible. We recommend making a series of questions "Not Visible" instead.
When you dispatch a form with conditional logic, the conditional logic will execute when the user opens the form, to get it into an appropriate starting state (as specified by your conditional logic rules). Then, the dispatched fields will get filled. Depending on your conditional logic, your dispatched data might conflict with the conditional logic rules.
Dispatched Data on Ignored Pages and Sections
In the normal flow of using a form, if a user activity "Ignores" a page or section that already has information in it, that data will "exist" again once the page or section is "Not Ignored".
However, if a page or section is set to "Ignored" as the form is first opening, any information dispatched into those pages will be cleared; so if a user action sets that section or page to "Not Ignored", that information will not exist.
If you need to dispatch information into Pages/Sections that can be "Ignored" in the form, ensure that they are "Not Ignored" in the starting state of the form, and that only a mobile user action will trigger them to be "Ignored."
Dispatched Data Being Overwritten by Conditional Logic Rules
Again, when a user opens up a form that has been dispatched to them, conditional logic runs to determine the starting state of a form, and then the dispatch data is filled.
If the "dispatcher" dispatched a value of "Pass" into a field in the form, but mobile users are reporting they did not receive that value, it is likely that a conditional logic rule is clearing/resetting/changing the value of that question as the form opens on the device.
*NOTE: If you are using conditional logic to "Set" an answer on a question, we highly recommend NOT dispatching to this question. The conditional logic and dispatched data may conflict and produce inconsistent results.