SurveyGizmo's CustomScript Action now supports the LUA programming language.
Legacy Custom Scripting Language Deprecation Plans
New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
In the long term, Legacy Custom Scripting Actions will be switched to read-only. Read-only scripts will continue to function; you will just be prevented from editing. The exact date on this is to be determined; we will send notifications well ahead of time.
While SurveyGizmo is one of the most flexible survey tools around, we get requests for customizations that are not available out of the box. This is where JavaScript and Custom Scripting can save the day. If you have scripting chops you can use the JavaScript action or the Custom Scripting action to achieve the survey of your dreams.
As part of our core randomization options, you have the ability to randomize or shuffle column and row order in a grid question. However, there is not a built-in feature to show a random subset of the rows in your grid question. Fortunately, it's pretty easy to script. We'll cover the steps to use a pretty simple script to accomplish just this. These steps assume a basic familiarity with Alchemer and programming.
There are two approaches you might want to take when randomly showing a subset of rows from the grid.
You might want to simply show a reduced number of grid rows to reduce respondent burden and fatigue and ultimately gather better data. This script is covered below in Option 1.
You can also show a subset of rows based on the selected options from a previous question. This script is covered below in Option 1.
Set up your grid question. Our example grid question looks like the below.
In the interest of reducing respondent burden and fatigue, we only want to burden each respondent with responding to three of the ten rows in this grid question.
To set this up we added a Custom Script Action to the top of the page with the grid question and pasted the below script.
--Row IDs to be randomly hidden go here. Make sure they are comma separated, no spaces.
rowsHideRandom = {3,4,5,6,7,8,9,10,11,12}
--Number of rows you want shown from the list above. No quotes or commas are needed.
shown = 3
--Do not change after this line.
shuffled=tableshuffle(rowsHideRandom)
for key,question in pairs (shuffled) do
hidequestion(question,true)
end
for i=1, shown do
hidequestion(shuffled[i],false)
end
Required Customizations
In the script above you will need to customize variables highlighted in yellow in order to make the script work in your survey.
rowsHideRandom - Replace this list with the question IDs for your grid rows.
shown - Change this to the number of rows you wish to show.
Option 2: Show rows that correspond to previously selected options
Set up your source question and follow-up grid question. Our example source and grid questions look like the below.
We only want to burden each respondent with responding to a maximum of three rows that correspond to their selections in the previous Checkbox question.
To set this up we added a Custom Script Action to the top of the page with the grid question and pasted the below script.
source = 2 -- Multiple choice source question ID
targetgrid = 4 -- Target Grid question ID
shown = 3 --select 3 to show
-- Replace the key text with the text of your row headers and the numbers with the row question IDs
vals = {}
vals["United"] = 5
vals["Delta"] = 6
vals["Southwest"] = 7
vals["Frontier"] = 8
vals["American"] = 9
vals["Alaska"] = 10
vals["JetBlue"] = 11
vals["Air Canada"] = 12
vals["Virgin America"] = 13
vals["Continental"] = 14
vals["Spirit"] = 15
--Get all the IDs for each row in target grid and set each to being hidden
targetskus = gettablequestionskus(targetgrid)
for key,question in pairs (targetskus) do
hidequestion(question,true)
end
options_selected = getvalue(source) -- get all options selected
rowidselection = {} -- a new array to hold the row ids of the grid to randomize from
for key,value in pairs(options_selected) do
table.insert(rowidselection, vals[value])
end
--shuffle the array
shuffled = tableshuffle(rowidselection)
--set the rows to show
for i=1, shown do
hidequestion(shuffled[i],false)
end
Required Customizations
In the script above you will need to customize variables highlighted in yellow in order to make the script work in your survey.
source - The question ID of the source question you wish to use to determine which rows will show.
targetgrid - The question ID of the target grid you wish to affect.
shown - Number of random rows to be shown.
vals - Replace the key text with the text of your row headers; make sure to preserve the quotes. The value numbers with the row question IDs.