Conditional Logic: Best Practices

 

Note: This is a limited-release feature. It can currently be added to your forms by our Professional Services team. Please contact your ProntoForms account manager for more information.

About

While conditional logic in forms simplifies mobile users' workflow, building it can be complicated. 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.

 

Definitions

This section will describe all the parts of a conditional statement using a part of a room inspection form as an 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. 

 

Condition: In a conditional statement, the condition is the part being evaluated as true or false. Our first condition in our room inspection example is:

If the room being inspected equals the common room...

 

Operator: The operator is the (usually mathematical) symbol that forms part of the condition. Common operators include (but are not limited to): > < =. In our room inspection example, all the operators are "equals."

If the room being inspected equals the common room...

 

Action: The action is what happens when the condition is evaluated. In our example, the actions are to show and hide sections based on the conditions being true.

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

 

Rule Joiner: When setting up your conditional logic section, you need to choose if all conditions must be true for the action to happen, or if just one condition needs to be true. These are rule joiners. ProntoForms uses AND (all conditions must be met) and OR (one condition must be met) as join rules.  An example of this in our Room Inspection form might be:

If the number of questions marked Passed is less than 3, AND the lights are not working, then show the Failed Inspection page.

[ top ]

 

Conditional Logic Validation

Form validation for conditional logic will catch many errors, but not all. Currently, the following are checked in various configurations (compatible operators, conditions, and actions):

  • Comparing two questions (e.g. If Q3 is less than Q1)
  • Correct data type for the operator
  • Valid actions for control and data types

Form validation cannot check for logic mistakes. For more information, read the Common Mistakes section below.

[ top ]

 

Common Mistakes

Non-Sequential Logic: All conditional logic must be sequential.

Valid conditions:
  • If Q1 = 3 and Q4=Fail, then hide Q5

Invalid Conditions:

  • If Q1=3 and Q4=Fail, then hide Q3

This kind of condition is not allowed.  

  • All questions that an action is performed on must occur after the last trigger question
  • All sections that an action is performed on must occur after the last trigger question
  • All pages that an action is performed on must occur after the last trigger question 

 

Conflicting Conditions: It is possible to make questions impossible to access despite being Required, or to make conditions that cannot be true. To avoid this:

  • Check your logic. Questions that are Required should never potentially be SetQuestionNotVisible.
  • Avoid mistakes such as:
    If Q1 = 5 and Q1 < 3, then do this, or
    If Q1 =3  and  If Q1=4, then hide Q2.

 

Conflicting Actions: As with conditions, it is entirely possible to set conflicting actions on the same question. Some common examples:

  • If Q1 =5, then hide Q2 and show Q2  
  • If Q1 =3 then show Q2   —  If Q2=3 then hide Q2 (Note: If these are separate conditions, it is valid.)

 

Setting question values: There are a number of considerations when using the SetQuestionValue (see below) action.

  • If Q1 sets Q5's value, but Q3's response hides Q5 from the mobile user, Q5's value will still be sent to the backend system. Consider whether this is needed and choose to ResetQuestionValue or ClearQuestionValue.
  • Actions contained within ELSE statements must reset or undo the actions contained in the IF statement. This is important because it prevents users who go back and change their minds from seeing irrelevant information.

  • If you set the value of a question with logic, also set that question as Read Only at the same time. If a user tries to change the value of a question being set by logic, the logic will continuously overwrite any changes they try to make.

 

Dispatching into Ignored Pages: When creating pages or section.that are ignored when you open the form, please be aware that any data dispatched into those pages will not be there if a condition makes the page or section un-ignored. 

 [ top ]

 

Tips

Unique Question Labels: Tying together logic across multiple pages of automatically-generated question labels can be difficult. Creating unique, meaningful question labels can make the process easier to track.

Where to find your logic: The web portal displays logic in two places based on where it applies:

  • Form level logic is displayed at the bottom of the "Pages & Questions" tab in the portal.
  • Repeat level logic is only visible on the "Info" button for the repeat section in the "Pages & Questions" tab.

[ top ] 

 

What happens when users change their mind or go back to earlier questions?

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.
  Conditional Statement Result
"Good" ELSE If Q1 <50
  • Set Q2 to "Fail"
  • Show Page 2
  • Show Q3
  • Set Q3 to Required
Else
  • Reset Q3
  • Hide Page 2
  • Hide Q3
  • Set Q3 Not required

This "ELSE" defines what to do if Q1 is not <50. This causes the following sequence:

  1. User sets Q1=45
  2. First set of actions fires
  3. User changes their mind, sets Q1=70
  4. ELSE actions undo the earlier actions, reverting them to a default state.

 

"Bad" ELSE  If Q1 <50
  • Set Q2 to "Fail"
  • Show Page 2
  • Show Q3
  • Set Q3 to Required
Else
  • Reset Q3

 This "ELSE" condition only works on the first encounter with the question. The sequence would be: 

  1. User sets Q1=45
  2. First set of actions fires
  3. User changes their mind, sets Q1=70
  4. ELSE action will say "PASS", but the other actions will remain "active". The user will still see:
    • Q3
    • Page 2

 

What happens to question/page data?

As discussed in Hidden Questions, Sections, and Pages, there are different ways of hiding a question, page, or section. Page and Section level actions override Question level actions.

SetPageIgnored/SetSectionIgnored Behavior SetQuestionNotVisible behavior

When a page is set Ignored, the data does not exist as far as the mobile users are concerned. The data will not be submitted with the form.

The user-entered data will remain on the mobile device. This prevents data loss if the user chooses an answer on a later question that sets the page to NotIgnored.

Data on Ignored pages will not be available for downstream calculations, digit extractions, or string concatenation. It will be ignored in any later questions that refer to it and any reports.

As Ignored pages do not exist to our users, any Required questions on these pages will also be ignored.

If set NotVisible, the question is hidden from the mobile user. If data has been entered, it will remain and will be submitted, and can be used for downstream calculations.

If the section or page is set to Ignored then the Ignored behaviour takes precedence and no data will be transmitted or be available for calculations. 

[ top ] 

  

Hidden Questions, Sections, and Pages

A common consideration is whether you want the information in hidden pages, sections, or questions to be submitted or cleared. The following actions are used to adjust this:

Question Level Actions Definition Notes On Use

SetQuestionVisible

SetQuestionNotVisible

The question becomes visible/invisible on the device. If set Visible, the question will show any default values, and if set Required, will require an answer as normal.

If set NotVisible, the question is hidden from the mobile user. If data has been entered, it will remain and will be submitted, and can be used for downstream calculations

If setting a question to NotVisible, consider whether you want to use ResetQuestionValue or ClearQuestionValue at need to prevent unwanted downstream effects.

If the section or page is set to Ignored (see below) then the Ignored behaviour takes precedence and no data will be transmitted or be available for calculations.

ClearQuestionValue This clears the question's user-entered and default value. It is essentially 'delete' for a question's value.  
ResetQuestionValue This resets the question's value to the default, erasing any user-entered data. Add a Reset to questions that are hidden by conditional logic to prevent extra values being sent without the users' knowledge. 

 

Page and Section Level Actions Definition Notes On Use

SetPageIgnored

SetPageNotIgnored

When a page is set Ignored, the data does not exist as far as the mobile users are concerned. The data will not be submitted with the form.

The user-entered data will remain on the mobile device. This prevents data loss if the user chooses an answer on a later question that sets the page to NotIgnored.

As Ignored pages do not exist to our users, any Required questions on these pages will also be ignored.

Data on Ignored pages will not be available for downstream calculations, digit extractions, or string concatenation. It will be ignored in any later questions that refer to it and any reports.

SetSectionIgnored

SetSectionNotIgnored

When a section is set Ignored, the data does not exist as far as our customers are concerned. The data will not be submitted with the form.

The user-entered data will remain on the mobile device. This prevents data loss if the user chooses an answer on a later question that sets the section to NotIgnored.

As Ignored pages do not exist to our users, any Required questions on these pages will also be ignored.

Data on Ignored sections will not be available for downstream calculations, digit extractions, or string concatenation. It will be ignored in any later questions that refer to it and any reports.

 

For more detailed information on which controls and data types these actions can be used on, please read Conditional Logic: Supported Actions.

 [ top ]

 

Comparing Two Questions: Compatibility

When comparing two questions, 

i.e.

  • If Q3 is less than Q1...
  • If Q3 is between Q2 and Q1
  • If Q3 contains Q1

Whatever is being compared to Q3 has to be valid for comparison. 

 

Data Type Can Be Compared To 

Integer

Integer, Decimal, Monetary Value, Duration, Calculation, Duration Calculation, Aggregation
Decimal Integer, Decimal, Monetary Value, Duration, Calculation, Duration Calculation, Aggregation
Monetary Value Integer, Decimal, Monetary Value, Duration, Calculation, Duration Calculation, Aggregation
Date Date
Time Time
Date/Time Date/Time
Duration Duration, Integer, Decimal, Monetary Value, Calculation, Duration Calculation, Aggregation

FreeText

Freetext can equal or contain:

  • Freetext 
  • URL
  • Email
  • Phone Number
  • String Concatenation 
URL

URL can equal or contain:

  • URL
  • FreeText 
Email

Email can equal or contain:

  • Email
  • FreeText
Phone Number

Phone Number can equal or contain:

  • Phone Number
  • FreeText
Yes/No Yes/No (equals only)
Signature, Image, File, Audio, Barcode,
Geolocation, CreditCard, Magstripe, Information
Cannot be compared to anything

[ top ]   

 

What ProntoAdmins can see on the portal

Conditional logic is visible to ProntoAdmins on the Pages and Questions tab of the form, underneath the question/section labels. This is another area where setting clear, logical question labels aids in making conditional logic human-readable. 

The web portal form builder does not allow construction of V2 forms.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

  • Avatar
    Robert Oliver

    When will the V2 Form builder be available?