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")]

As piping into rows of Textbox List questions is not available using the built-in piping feature, this script will query the answers from a source Checkbox question and filter the option list in a target Textbox List question accordingly. For this to work, the option titles of the Checkbox question must correspond exactly to the option labels of the Textbox List question. If no options are selected in the source question, the script jumps to a specified survey page (the next page in this case).

See the script in action 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

This script will query the answers from a source Checkbox question and filter the option list in a target Textbox List question accordingly.

--filter a textbox list of labels by a source checkbox question

--option filtering based on source question 
sourceID = 2 --checkbox questionID
targetID = 3 --textbox list questionID
next_pageID = 2 -- pageID of the next page to jump to if there are no options selected in source

--get t list of options for target q
tgt_opts = getquestionoptions(targetID)
source_labels = getquestionoptions(sourceID)
source_rvalues = getvalue(sourceID)
source_values = {}

--construct a usable array of option_sku => checkbox label for selected checkbox options
for sku,r_value in pairs(source_rvalues) do
  	 
  table.insert (source_values, sku, source_labels[sku])
  
end

--hide options in target question, unless they are in ticked in the source question
for key, label in pairs (tgt_opts) do
  
  hideoption(targetID, label,false)
  
  --if option value was not selected in source question, hide it from target q
  if(not(in_array(label,source_values))) then
    
     hideoption(targetID, label,true)
    
  end
  
end

if(count(source_values) == 0) 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 question.

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

next_pageID - The page to jump to if no options are selected in the Checkbox question (and therefore the page with the textbox list question is skipped.