By default, a conditional sequence does not allow you to count the number of options selected by a participant in a Multi Choice question. Follow the instructions below to use a script in a conditional sequence to filter questions based on the number of responses to a Multi Choice question.
Detailed Steps
Create a Conditional Sequence:
- On the Authoring Navigation Bar, hover over Folder, and then select Conditional Sequence.
- Select the Conditional Sequence in the tree.
- Expand the Properties section below the Filter Editor.
- Under Condition Using, select Script.
- Click Save.
Prepare the Script in Notepad:
- Open Notepad or a similar text editing tool.
- Copy the script below into Notepad.
- Edit the script in Notepad by doing the following:
- Replace MULTICHOICE_QUESTION with the name of the Multi Choice question.
- Replace NUMBER with the number of selections on which to base the condition. This value must be an integer. Do not spell out the number.
- Setup the IF statement ( if (cq.GetSelectedAnswers().Length > count) ) with the desired scripting operator from the table below.
Condition | C# Scripting |
Equal To | == |
Not Equal To | != |
Greater Than | > |
Less Than | < |
Greater or Equal To | >= |
Less Than or Equal To | <= |
Script:
/* Script Name: How do I add a conditional sequence based on the number of selections made in a previous multi-choice question? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ EnterCondition = false; ChoiceQuestion cq = MULTICHOICE_QUESTION; int count = NUMBER; if (cq.GetSelectedAnswers().Length > count) { EnterCondition = true; }
Insert the Script into your conditional sequence:
- Copy the completed script into the Conditional Sequence textbox.
- Click Save.
- Create additional questions in your conditional sequence. These questions will be answered by those who enter the conditional sequence based on the criteria you have prepared in the script.
- Click Validate and test your study.
Example Script:
// This script counts the number of responses in a question called FavoriteCar // If the respondent selected less than three responses, the script sets EnterCondition to true and system will enter the conditional sequence. Otherwise,the Conditional Sequence is skipped. EnterCondition = false; ChoiceQuestion cq = FavoriteCar; int count = 3; if (cq.GetSelectedAnswers().Length < count) { EnterCondition = true; }
Note: The question names used in scripts are case-sensitive. Ensure that you use the exact question names as they appear in the Questionnaire tree of the survey.
Comments
0 comments
Article is closed for comments.