Tip: Are you using scripting with power surveys to pipe/hide/mask answer options from one question to another question? You can now do this in surveys with no need for scripting. For more information, see Carry Forward Answers in the Surveys documentation.
The terms pipe, hide and mask are used interchangeably. The common goal is to show options based on a previous question. We will use the word mask throughout this article.
This script will work in the following question types:
Previous Question Type | Masking Question Type |
|
|
Note:
- The script below is not supported for mobile responding.
- The maximum number of items allowed in a Rank Order Sort is 20.
- Please be aware that when masking a rank order question, the "Total Participant" count in Analyze will match the number of members that were able to rank the first answer option programmed in the questionnaire. For reporting purposes, to find the base size for the number of unique members that provided an answer, switch to the table view and observe the "Total" row.
Tip: Did you know you can mask answers into a Rank Order question in surveys, without having to use scripting? For more information, see Mask answers in a question.
Detailed Steps
- Create your source question as required (the items in the Rank Order question will be masked based on this question).
- Create your Rank Order Grid/Sort question as required.
Ensure that the list of items at this question is the same as the options in your source question. - Select the Rank Order question in the Questionnaire Tree. In the Properties section of the question, enter the maximum number of ranks you require under Required row count for Rank Order Grid or Number of Ranks for Rank Order Sort.
Note: If the question is a grid type and the maximum number is less than total number of rows you have in the question, please add the How do I hide rank order grid columns? script first. See link in the More information section below. - Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad) and make the following changes:
- Change Q_PREVIOUS to the name of your previous question that you want to reference for masking.
- Change Q_MASKING to the name of your rank question.
- Make further changes to the script to achieve the desired logic.
Show rows that have specified number range allocated:- Copy this script and replace the line of code in red
int[] showRows = ArrayUnion(GetAllocRowsIfBetween((GridSequence)prevQ, MIN, MAX), new int[] {-1});
- Change MIN to the minimum number value required at the allocation question to be shown at the rank order question.
- Change MAX to the maximum number value required at the allocation question to be shown at the rank order question.
- Copy this script and replace the line of code in red
- (Optional) Find the line of code in red. Change -1 to item numbers you would like to show all the time (separated by a comma if there are multiple), e.g. Other option.
If you do not have any items to show permanently, leave it as is. - Insert the completed script into the Script section of your rank order question by doing the following:
- Select your rank order question in the Questionnaire Tree.
- In the Scripting section of the page, click Edit Scripts.
- Paste the script into the On Load tab.
- Click Save.
- Validate and test your survey.
Script
/*Script Name: How do I pipe / hide / mask options from an Allocation question into a Rank Order question for a desktop-only survey? (Power Surveys)
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.
*/
IOrderable prevQ = Q_PREVIOUS; GridSequence rankQ = Q_MASKING; int[] showRows = ArrayUnion(GetSelectedIndexes((ChoiceQuestion)prevQ), new int[] {-1}); /************ Do not edit below ************/ Show(rankQ, showRows); int showLen = 0; foreach(int i in showRows) if(i > 0) showLen++; int origLen = rankQ.MinimumRowsRequired; if(showLen == 1){ SetAndSkipIfOneItemShown(rankQ, 1); } else if(showLen < origLen){ if(!rankQ.SupportsMobile){ //grid HideColumns(rankQ, GetIntArrayBetween(showLen+1, origLen)); } rankQ.MinimumRowsRequired = showLen; }
More Information
Read this Knowledge Base article to learn more about How do I hide rank order grid columns?
Comments
0 comments
Article is closed for comments.