Tip: You can do this in modern surveys and the script is now available! For more information, see How do I ensure each row of an Allocation question does not exceed a maximum value? (Modern Surveys).
This script will check each response entered in an Allocation Grid, and display an error message if any response exceeds a specific maximum value.
Note: This script will not work on an Allocation Slider.
Detailed Steps
Adding and setting up the Questions:
- In Power Survey Authoring, click on the Questionnaire tab.
- Create your Allocation Grid question.
- Set the minimum total of the Allocation Grid to 0 and the maximum total to 100 (or any number that is the total expected amount).
- Create a hidden Single Choice question to store the error message text:
This answer text will need to be translated for each language in your study since the error message being displayed to the respondent will appear in the current survey language.- Create a Single Choice question.
- Select the Hidden checkbox located at the top right corner of the question page.
- Add an answer that reads: Please ensure each answer is between 0 and 100. This can be edited if necessary.
- Change the precode of this answer to alloc_row_err.
Prepare the script in Notepad:
- Open Notepad or a similar text editing tool.
- Copy the script below into Notepad.
- Change ALLOCATIONNAME to the name of your allocation grid.
- Change RANGE to the desired maximum value for each row.
- Change ERR_MSG to the name of the hidden single choice question containing the error message.
- Save the completed script in Notepad.
Script:
/* Script Name: How do I ensure each row of an allocation grid does not exceed a maximum value? 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. */ if (!IsATR){ try{ int range = RANGE; //update max value per row, e.g. 99 GridSequence gs = ALLOCATIONNAME; //update name of grid foreach (ShowQuestionAction sqa in gs.WorkflowSteps){ VerbatimQuestion vq =(VerbatimQuestion)sqa.VerbatimQuestion; if(vq.Value != null){ if(!Between (0,range,vq.IntValue)){ NewError(((Answer)ERR_MSG.FindAnswerByCode("alloc_row_err")).Html+" "+range); return; } } } } catch(Exception e){ NewError("Error: " + e); } }
Insert the completed script into the Script section of your Allocation Grid Question:
- Copy the completed script from Notepad.
- Select the Allocation Grid question in the Questionnaire Tree.
- In the Scripting section of the Allocation Grid Question, click Edit Scripts.
- Paste the script into the On Validate tab.
- Click Save.
- Validate and test your survey.
Comments
0 comments
Article is closed for comments.