Lua Scripting Resources

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language.


Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. 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.
  3. 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.


 Go to our Legacy Scripting Documentation.

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.


[article("bodfy")]

This example script works for conditional piping from a Checkbox Grid question to any other Grid question, as all Grid questions in Alchemer have the same structure, with each row corresponding to a separate questionID.

In this example script, we are going to only show the rows in the target radio button grid questions for which any of a specified set of column answers were checked in the source grid.

For this to work, the target grid question must be set up with the same row titles as those from the source checkbox grid question.

See the script in action in an example survey.

OR

Add a survey with this script and setup to your account.

Features and functions used in this script:

The Script and Setup

The script below requires plugging in the questionID of the source checkbox grid question, the questionID of the target radio button grid question, the ID of the next page to jump to (should there be nothing to display on the page with the target question), and an array with the comma-separated, single quote marks enclosed names for each of the options from the checkbox grid columns you would like to be in the qualifying answers to have that row displayed in the target radio button grid question.

sourceID = 34
targetID = 3
next_pageID = 6

--an array of selected options which qualify that row to be shown in the subsequent grid
target_options = {'I have played this game frequently','I still own this game'} 

checkboxtable = array_flip(gettablequestiontitles(sourceID)) --row title => id
radiotable = array_flip(gettablequestiontitles(targetID)) --row title => id

hidden_rows = 0
for title,id in pairs(checkboxtable) do --loop through the checkbox table question rows
   row_values = getvalue(id) --get the values, each row is like a separate checkbox question
   
   hidequestion(radiotable[title], true) --initially hide the corresponding row from the radio button table
   hidden = true
  if(type(row_values) == 'table') then
  for row,value in pairs(row_values) do -- loop through the checkbox question row
     if(in_array(value, target_options)) then -- if the value checked is in the target options array, then unhide the corresponding row in the radio table 
     	hidequestion(radiotable[title], false) --unhide the corresponding row from the radio button table
    	hidden = false
   	end
  end
 end
   -- here we increment the counter for hidden rows in the radiobutton table
   if(hidden == true) then
      hidden_rows = hidden_rows + 1
   end
end


if(hidden_rows == count(radiotable)) then
   jumptopage(next_pageID)
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.

sourceID - This variable will indicate the question ID of the source Checkbox Grid question.

targetID - This variable will indicate the question ID of the target grid question.

next_pageID - The page to jump to if no options are selected in the Checkbox Grid question such that the corresponding rows are displayed in the target grid question (and therefore this question has no rows so the page should be skipped).

target_options - The array of options ticked per row which you wish to qualify that row for being displayed in the target grid question, formatted as you see in the script, encased in single or double quotes and comma separated with no comma after the last one.