This script will count the number of columns selected in a Grid question, with the option to specify particular rows. The final count will be stored in a numeric question, which can then be used in a conditional sequence to ask follow-up questions if necessary.
This script will only work for the following question types:
- Single Choice Grids (standard and visual)
- Multi Choice Grids (standard and visual)
- Scale Slider Grids
- Single Choice Card Sorts: rows=cards, columns=categories
- Single Choice Magnetic Boards: rows=magnets, columns=boards
- Multi Choice Magnetic Boards: rows=magnets, columns=boards
Example
You are asking a participant to select all the brands of devices they own at home. You have a Multi Choice Grid question where the brands are set up as the rows (Apple, Sony, Microsoft - in that order) and the device types are set up as the columns (computer, television, mobile phone, tablet, etc).
You then want to ask a follow-up question to all respondents who have more than one device for Apple and Sony (i.e. more than one column selected across the Apple or Sony rows).
Detailed Steps
- Create your Grid question as required.
- Create a Numeric question that will be used to store the final count of the number of columns selected. Hide this question so participants do not see it.
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change Q_NAME to the name of your grid question.
- Change Q_NAME_COUNT to the name of your numeric question.
- Change LIST to row numbers (separated by a comma if multiple) e.g. 1,2,3
- Insert the completed script into the Script section of your grid by doing the following:
- Select your grid question in the Questionnaire Tree.
- In the Scripting section of the question, click Edit Scripts.
- Paste the script into the On Exit tab.
- Click Save.
- (Optional) Now you can build a condition referencing this hidden Numeric question.
- Validate and test your survey.
Script
/* Script Name: How do I save the number of columns selected in a previous grid 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. */ GridSequence gs = Q_NAME; VerbatimQuestion vq = Q_NAME_COUNT; int[] specifiedRows = {LIST}; int[] shownRows = GetRowsIfAnySelected(gs, GetAllColumnIndexes(gs)); int[] finalRows = ArrayIntersect(specifiedRows, shownRows); ArrayList selectedCols = new ArrayList(); foreach(int r in finalRows){ ChoiceQuestion cq = CQ(gs.Name+"_"+(r-1)); selectedCols = ArrayUnion(selectedCols, new ArrayList(GetSelectedIndexes(cq))); } Set(vq, selectedCols.Count);
More Information
Please click on the webhelp links below for more information:
Comments
0 comments
Article is closed for comments.