In this document, we will explain how you can implement your own logical expressions and syntax within the WeGuide system.
- What is conditional questionnaire logic?
- Which operators are supported?
- Dynamic variables
- Function
- Questions
- How to write syntax
What is conditional questionnaire logic?
- Within each questionnaire, you have the ability to implement conditional logic, so that a user can skip certain questions based on their responses.
- For example, if someone says no to “Do you ever drink alcohol?”, you can make other questions are shown/hidden based on this response.
Which operators are supported?
- Please see the following operators and methods which are supported within the WeGuide logic:
=
!=
>
>=
<
<=
and
or
| Equal to |
|
| Not equal to |
|
| More than than |
|
| Greater or equal to |
|
| Less than |
|
| Less or equal to |
|
| And |
|
| Or |
|
| Add |
|
| Subtract |
|
| Multiple |
|
| Divide |
|
Dynamic variables
- A dynamic variable is a variable whose address is determined when the program is run.
today
- provides the current date
Example:[question_1] = today
Functions
String/Text functions
lowercase
- Lower case the text
Example:lowercase([question_2]) = 'abc'
uppercase
- Upper case the text
Example:uppercase([question_2]) = 'ABC'
contains
- To check whether the text contains another text
Example:contains([question_3], 'help') = true
Date functions
date
- Provides to input date, date and time, or time
Examples:date(2021-12-30)
date(2021-12-30 14:00)
date(18:00)
datediff
- To get the difference between two dates in number (can be negative as well)
it takes three arguments:
1.date1
- a date input as adate
function, a variable, ortoday
2.date2
- a date input as adate
function, a variable, ortoday
3.unit
- day, month, or year
For examples:datediff([question_dob], today, year) >= 18
datediff([question_last_usage], today, month) < 6
datediff([question_last_test], today, day) = 1
(yesterday)datediff([question_last_test], today, day) = -1
(tomorrow)
Note: it provides a negative number if date2
is less than date1
.
For example, this evaluates true:
datediff(date(2021-12-10), date(2021-12-01), day) = -9
Questions
The ID by which we identify a question is called the short name
. When you add a question, you will be able to change it. The short name is always prefixed by the survey ID. In the example underneath questionnaire ID is lifestyle
and the Question ID is lifestyle_age
Underneath a description of how you can write the logic for each question type. If a question type is not mentioned here, then currently we don’t support conditional logic for those question types.
Multiple choice question
In order to write logic around your multiple-choice question, use the option IDs as provided after you have saved the question. Each option will have a true
or false
value, which can be used for your logic.
For example:
Only show question 5 if, during question 3, the user has selected only the option with ID 1415
[lifestyle_food_option_1415] = true
- Only show question 5 if, during question 3, the user has at least selected option ID 1416 and option ID 1417
[lifestyle_food_option_1416] = true and [lifestyle_food_option_1417] = true
- Only show question if option 1416 or 1417 is selected
[lifestyle_food_option_1416] = true or [lifestyle_food_option_1417] = true
Only show question if option 1416 and 1417 is selected
[lifestyle_food_option_1416] = true and [lifestyle_food_option_1417] = true
Only show question if options 1416 and 1417 are not selected
[lifestyle_food_option_1416] != true and [lifestyle_food_option_1417] != true
Single Choice Question
[lifestyle_food] = "Not at all"
[lifestyle_food] = [option_1416] or [lifestyle_food] = [option_1417]
Email Question
[lifestyle_question_1] = "mumbai@email.com"
Number Question
[lifestyle_question_1] = 2
[lifestyle_question_1] > 3 and [lifestyle_question_1] < 7
[lifestyle_question_1] != "Mumbai" or [lifestyle_question_2] > 2.4
Date question
[lifestyle_question_1] = date(1992-01-22)
[lifestyle_question_2] >= date(1992-01-22)
[lifestyle_question_1] != date(1992-01-22) or [lifestyle_question_2] > 2
Date Time Question
[lifestyle_question_1] = date(2021-10-21 18:19)
[lifestyle_question_1] < date(2022-10-21 18:19) and [lifestyle_question_1] > date(2021-10-21 18:19)
[lifestyle_question_1] != date(2022-10-21 18:19) or [lifestyle_question_2] > 2
Time Question
[lifestyle_question_1] = date(18:19)
[lifestyle_question_1] > date(18:19)
Text Question
[lifestyle_location] = "Mumbai"
[lifestyle_location] = "Mumbai" and [lifestyle_location]="Melbourne"
[lifestyle_location] != "Mumbai" or [lifestyle_age] > 2"
If you expect that the answer contains a '
, while writing the syntax, make sure you write it is \'
.
For example, I’ve already been tested will be“I\'ve already been tested"
. So the syntax will be something like this: [lifestyle_question_76]="I\'ve already been tested"
The text is case-sensitive and an exact match.
Range Slider Question
[lifestyle_question_1] = 4.2
[lifestyle_question_1] = 4.0 and [lifestyle_question_2] > 3.5
[lifestyle_question_1] != 5.6 or [lifestyle_question_2] > 2
Video & Photo question
The only logic currently supported is to check if a photo/video was taken or not.
[lifestyle_question_1] = false
[lifestyle_question_1] = true
How to write syntax
For conditional survey logic, you can use the questions as your variables.
Conditional logic in questionnaires can always be edited, irrelevant of the status of the questionnaire (draft, published).
To create a questionnaire go to: <yourtenant>.weguide.com.au/questionnaires
Click on a question and click on the tab “Conditional logic”. Here you can define when this question should be shown
In case nothing is entered or an invalid condition is entered, then the question will always be shown.
In case a condition is entered, then the question will only be shown if the condition is true.
Some tips:
Option ID. The option IDs can be found in details of the single choice or multiple choice question after it’s saved. Every option will get its own ID.
Question ID. The question_id can be found in the overview on the left after the question is saved.
Once you have written some conditional logic, it will look like this on your question. Save your question and test it out! Have fun :)
Use data points from previous forms in your conditional logic statement
In case you have added data points to your form, then you can also use them for your conditional logic.
- Make sure that you add the data point first to your form, before you use it in your conditional logic.
- Once added, you can refer to the variable the same way as you would do normally on a form.
- It is possible to do conditional logic based on
- Only data points from a previous form.
- Only show food_question_1 if
- drink_preference = option_12
- Only show food_question_1 if
- Only data points from a previous form.
- Currently we don't support doing conditional logic based on data from previous forms and current forms, that is planned for a future release.
- In case the participant hasn't completed the data point that you have added to the form, then the logic will never become true and the question will never show, similar to how the conditional logic is working for normal conditional logic.
Was the article missing some information or unclear? Please click on the thumbs down below and let us know how we can improve. Your feedback is always appreciated.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article