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.
The question which you would like to reference will be referred to as the previous question. The question that will be masked will be referred to as the masking question.
This script will work in following question types:
- Grid Question - Rows to Grid Question - Columns
Previous Question Type | Masking Question Type |
|
|
Detailed Steps
Note: Make sure that the options in the previous question and in the masking question have the same number of items and are in the same order.
- Copy the script of appropriate case from below.
- Select the masking question in the Questionnaire Tree.
- In the Scripting section of the masking question, click Edit Scripts.
- Paste the script into the On Load tab.
- Change Q_MASKING to the name of your masking question/page.
- Change Q_PREVIOUS to the name of your previous question.
Note: this can appear twice in the script depending on the case. - Change # to column/scale/bucket/board numbers (separated by a comma if multiple) of the previous question that must be selected in order to show up in masking question.
Note: # represents the position of the column item, it is not the precode. If you specify multiple number in one list, the item will be displayed if one or more of these column # was selected in the previous grid row. - Change -1 to item numbers you would like to show all the time (separated by a comma if there are multiple). E.g. 'None of these' option. If you do not have any items to show permanently, leave it as is.
- Click Save.
- Validate and test your survey.
Script
/*Script Name: How do I pipe / hide / mask columns in a Grid question based on the rows in a previous Grid question? (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.
*/
Case | Script |
Show selected answers from previous question | ShowColumns (Q_MASKING, ArrayUnion(GetRowsIfAnySelected (Q_PREVIOUS, new int[]{#}), new int[] {-1})); |
Show unselected answers from previous question | ShowColumns (Q_MASKING, ArrayUnion(ArrayDiff(GetAllIndexes(Q_PREVIOUS), GetRowsIfAnySelected (Q_PREVIOUS, new int[]{#})), new int[] {-1})); |
Example
ShowColumns (Q2, ArrayUnion(GetRowsIfAnySelected (Q1, new int[]{4,5}), new int[] {6}));
Q1
Comments
0 comments
Article is closed for comments.