How to set up Delayed Branching using Custom Scripting

Delayed Branching Senario:

For example in Q2 of the Survey you ask respondents to select their gender: Male/Female. Now based on this you want to display Q10 of the Survey only to Males and Q11 only to Females and all respondents should continue with the same question Q12 and the rest of the Survey.

When you use the Branch option under the tools console the Branching is executed immediately. The above example is that of delayed branching.

The script for the above requirement is as follows:

#if(${Q2} == 1)
 $survey.branchTo("Q10")
#end

#if(${Q2} == 2)
 $survey.branchTo("Q11")
#end
In the above script: Q2, Q10 and Q11 are question codes for the respective questions. The if statement checks if answer to Q1 was 1 (Male) or 2 (Female) and accordingly branches to Q10 or Q11

Following are the steps for setting this up:

Set up the basic survey with all the questions

Add the Custom Scripting/Scoring logic question after Q9 in the Survey

Set up the above Script in the Logic Question

Set up default Branching for Q10 and Q11 to Q12

Make sure there is a page break on Q9

How to check if a certain question is not answered?

#if(!${Q1})
 $survey.branchTo("Q3")
#else
 $survey.branchTo("Q2")
#end
The above script checks if Q1 is answered or not. If Q1 is not answered then the survey branches to Q3, else it branches to Q2.

Start your Free Trial