This script checks each response entered in an Allocation question. If an amount exceeds the maximum value set in the script, an error message will appear.
Detailed Steps
- In your survey, add a Page element.
- Add an Allocation question to the Page element.
- Open the Page element for editing and click the Scripting button.
- Copy and paste the script below into the On Complete tab.
- Replace ALLOCATION_GRID with the Allocation question name.
- Replace ROW_RANGE with the maximum row value.
- Click Save.
- Preview and test your survey.
Script
/*
Script Name: How do I record the sum from an Allocation question? (Modern Surveys)
To ensure your script works as expected, always copy the original script from the Script Library
found in the Alida Help Center. Failure to use the latest script from the script library may
cause unexpected results. */
const allocItems = response.getDataPoint("ALLOCATION_GRID").getItems();
var rowRange = ROW_RANGE;
// Loop through the allocation items and check the amount for each of them
allocItems.forEach(function(item) {
var value = item.get();
// check the number entered in each row does not exceed maximum value allowed
if (value > rowRange) {
response.setError("ALLOCATION_GRID", "Please check your responses and ensure each answer is not greater than " + rowRange);
}
});
Example
Comments
0 comments
Article is closed for comments.