Display conditions, complete guide

Compatibility:IdSurvey 7IdSurvey 8

Display conditions let you display an object of the questionnaire according to specific conditions.

Objects that you can apply Display Conditions to are:

  • answer options
  • grid/matrix rows
  • grid/matrix columns
  • advanced grid/matrix cells
  • questions
  • groups of questions
  • pages
  • sections
  • custom alerts

 

Conditions can include values such as:

  • answer codes
  • values inserted in text answers (text, numbers, dates), rating and sliders.
  • contact fields

 

Logical operators

Comparison symbols
These symbols can be used to compare two values.

  • == equal to
  • != different from
  • < less than
  • > greater than
  • <= less than or equal to
  • >= greater than or equal to

 
Negation
The negation symbol reverses the Boolean result of the condition. It must be placed before the condition.

  • ! negation

 

Refer to data

In IdSurvey Display Conditions you can refer to different types of data.

Answer code
By writing the question code as the first value, IdSurvey will compare it with the answer code written after the operator.

if( Q1 != 1 )
Checks if answer code 1 was not selected on question Q1.

Values from open end answers, grids, rating and slider
By writing question code between square brackets, IdSurvey will compare values inserted in open end questions, rating and slider.

if( [Q1] <= 50 )
Checks if the value inserted as answer in question Q1 is less or equal to 50.

if( [Q2.1] == 80 )
Checks if the value inserted in the row 1 of grid question Q2 is equal to 80.

if( [Q3.2.1] != 10 )
Checks if the value inserted in the cell made by crossing of row 2 with column 1 of 3D Matrix Question Q3 is different than 10.

Values drag&drop
By writing question code followed by the answer code of a drag&drop question between square brackets, IdSurvey will compare the position of that answer in the list.

if( Q1.1 == 1 )
Checks if answer .1 of drag&drop question Q1 is placed as first in the list.

if( Q1.3 != 1 )
Checks if answer .3 of drag&drop question Q1 is placed in a position different than the first in the list.

Values from contacts database fields
To refer to a value of the contacts database, you have to write the name of the field between curly brackets.

if( {gender} == m )
Checks if the field “Gender” of each respondent is populated with the value “m”

Notes

  • You can refer to a value inserted in (square brackets) only with open end questions, rating and slider. For this types of question IdSurvey records not only the answer code but also the value inserted by the respondent.
  • Only a single value for each simple question, one value for each row of a grid and one value for each cell of an advanced grid can exist. For more information check IdSurvey guide or the specific article of the Knowledge base.

 

Conventions

For convention, all conditions based on questions not shown give back a false result.
For example, if question Q15 was not shown because it was filtered, and the condition if( Q15 != 3 ) was applied to question Q20, question Q20 won’t be shown even if the answer is different than 3.
This convention ensures a more natural behaviour for the way the display conditions are generally conceived in a questionnaire.

You can avoid this convention using the operator not (negation). For example, if you apply the condition if( !Q15 == 3 ) to question Q20, this question will be shown even if question Q15 was not displayed. Show if at question Q15 was not selected answer option 3.

 

Operators AND and OR (&& and ||)

The use of AND and OR operators combines conditions to design logic of any complexity.

The symbol “And” is: &&

The symbol “Or” is: ||

if( Q1==99 || ( Q1==1 && Q1==2 ) )

The question Q3 is displayed if I selected the answer with code 99 at the question Q1 or if I selected both “1” and “2” at question Q1.

As you can see, the condition Q1==1 && Q1==2 is written between brackets. This is used to indicate the order of processing. In this example, the result of the condition is processed with the condition outside the bracket, so Q1==99 or [result of the sub-condition]

Note:

  • Without brackets, IdSurvey will process AND conditions before OR conditions. Even if we would suggest always using brackets in order to avoid ambiguities of the order of elaboration, the condition of the example above could also be written without brackets.

 

Algebraic calculation

You can formulate algebraic expressions of any complexity within the conditions using the mathematical operators sum, subtraction, multiplication, and division (+, -, *, /).

if( ([Q1]+[Q2]) <= 100 )
it checks if the sum of the numerical answers given to question Q1 and Q2 is less than or equal to 100.

if( [Q5] == (retrieve(Q1, open)/2) )
it checks if the number inserted in the open-end option of question Q5 is equal to half of that entered in question Q1.

 

Functions

IdSurvey provides a number of functions that can be used in display conditions, in FlowScript and in IdCode. The functions allow you to perform checks on questions, contact fields or quota status. For example, check how many answers have been selected to a question with multiple answer options or check if a certain quota is closed, etc...

Other special functions allow you to process strings, retrieve the label of an option of a drag&drop question by position (ranking) and much more.

CountCodeIt allows you to count the number of options selected.if(CountCode (Q1) >= 3)

It checks if on question Q3 three or more options were selected.
ResponsesCodeOfIt gives back the codes of the answers selected in a question.if(Q2==responsesCodeOf(Q1)

It checks if the answer selected at question Q2 has the same code of that selected at question Q1.
CountResponsesWithCodeIt allows you to count the number of questions to which a specific response code was answered.if(CountResponsesWithCode(Q1,Q2,Q3,Q4,Q5,Q6,99) >= 3)

It checks if code 99 was answered to a minimum of three questions among Q1, Q2, Q3, Q4, Q5 and Q6.
CountResponsesWithTextIt allows you to count the number of questions to which a specific text or number was answered.if(CountResponsesWithText (Q1,Q2,Q3,Q4,Q5,Q6,'sea') >= 3)

It checks if the word "sea" was entered on at least 3 of the text answers on questions Q1, Q2, Q3, Q4, Q5 and Q6.
CheckQuotaIt allows you to verify if a certain quota is open or full.if(CheckQuota ('Parents') == 1)

It checks if the quota "Parents" is full.
CompareDateIt compare two dates.
It gives -1 if the first date precedes the second one, 0 is they are the same and 1 if the first date is subsequent to the second one.
if(compareDate({date_of_birth}, ‘2010-10-01') == -1)

It checks if the date in the "date_of_birth" field precedes the date specified.
ModuleIt gives back the string CATI, CAWI or CAPI according to the module with which the interview is currently distributed.if(module()==cawi)

It checks if the interview is currently distributed via CAWI.
ContainsTextIt allows you to verify the presence of the specific text within an open-ended answer.if(ContainsText ([Q1],'sea')==1)

It checks if the text answer to question Q1 contains the word "sea".
StartWithTextIt compares the beginning of a string with a specified string.if(StartWithText({Mobile},'+39')==1)

It checks if the field Mobile starts with “+39”.
EndWithTextIt compares the end of a string with a specified string.if(EndWithText({Identification},'123')==1)

It checks if the field Identification ends with “123”.
GetVariableIt allows to obtain the value of a variable (on the contact or on a question) dynamically creating the name of the variable itself.getVariable('{date_of_birth_son_'+{ison}+'}')

It obtains the value of the "ison" variable (for example 3) and uses it to generate the name of the variable "date_of_birth_son_3" getting the value related.
JoinIt allows to force the combination of strings preventing that these are interpreted as numbers. For example 10+02+12 goes 24, while join(10,02,12) gives 100212.join(10,02,12)

It creates the string 100212.

join(text,02,[Q1])

It creates the string text02openResponseQ1.
RandomIt creates a random number between the minimum number and the maximum number indicated. You can specify a name to save the number generated in order to use it afterwards.random(1, 10)
It creates a random number between 1 and 10.

random(1, 10, 'my random number')

It creates a random number between 1 and 10 and saves it with the name specified. Using the same syntax (in the FlowScript of any other page of the questionnaire) the number saved and generated the first time will be called again. 
ReplaceIt replaces the specified text within a string.

(Available starting from IdSurvey 8.1)

Replace([Q1], 'car', 'bus')

It gives back the string of the text answer of question Q1 replacing the word "car" with "bus".

Replace({phone}, '+39', '')

It gives back the field phone without the prefix +39.
GetItemByRankingIt gets back the label or the code of the item according to its position.

(Available starting from IdSurvey 8.1)

GetItemByRanking(Q1, 1, label)

It gives back the label of the element in first position in the drag&drop question (or - for the matrix - it gives back the text of the row where the answer with code 1 is selected).

GetItemByRanking(Q15, 3, code)

It gives back the code of the element placed in third position in the drag&drop question (or - for the matrix - it gives back the text of the row where the answer with code 3 is selected).

GetItemByRanking(Q1, 1, auto)

or
GetItemByRanking(Q1, 1)

It gives back the label of the element in first position in the drag&drop question. If the label is not available you get the code.
RetrieveIt returns the answer selected and allows you to specify the data to be recovered and the formatting of the multiple answer separator.

(Available starting from IdSurvey 8.1)

retrieve(Q1)

or
retrieve(Q1, auto)

It gives back the open end answer (if available) or the label of the answer selected in question Q1. In case of multiple answers, you get all the options separated by the pipe character “ | ”.

retrieve(Q1, auto, ', ')

As the previous example but in case of multiple answers, you get all options separated by a comma and a space.

retrieve(Q1, opentext)

It gives back the text answer of question Q1.

retrieve(Q1, label)

It gives back the label of the answer selected in question Q1.

retrieve(Q1, code)

It gives back the code of the answer selected in question Q1.

retrieve(Q1, commentbox)

It gives back the text inserted in the comment box.

Leave A Comment?