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

In this example, we cover a script to conditionally show text elements based on the attributes that are rated highest in a MaxDiff question.

See this 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

  1. Add a MaxDiff question to the first page in your survey.
  2. Create the follow-up text elements or questions that you would like to conditionally show based on the highest ranked attributes in the MaxDiff Question. In our example, we have twelve text/instruction elements that display the attribute title: Humor, Strength, Attractiveness, Beauty, Compassion, Love, Kindness, Integrity, Empathy, Ambition, Passion, and Honesty.
  3. Make note of the question IDs of your corresponding text elements/questions. Question IDs are available to be displayed on the Build tab. If you don't see your question IDs, check out our Customize Survey Builder Tutorial.
  4. Add a Custom Script action on a subsequent page and copy and paste the below script and make the required customizations listed below.
-- SHOW TEXT/QUESTIONS BASED ON BEST RANKED FROM MAXDIFF
maxdiff = 2
ids = {6,7,9,10,11,13,14,15,16,17,18,19}
attributes = {[6]='Humor',[7]='Strength',[9]='Attractiveness',[10]='Beauty',[11]='Compassion',[13]='Love',[14]='Kindness',[15]='Integrity',[16]='Empathy',[17]='Ambition',[18]='Passion',[19]='Honesty'}

-- HIDE ALL TEXT/QUESTIONS
for key,id in ipairs(ids) do
  hidequestion(id, true)
end

-- GET THE ARRAY OF MAXDIFF RANKINGS
data = getvalue(maxdiff)

-- CREATE NEW ARRAY OF BEST RANKINGS
best = {}

for set,setdata in pairs(data) do
  best[set] = setdata['best']
end

-- LOOP THROUGH ATTRIBUTES ARRAY AND SET THE QIDs TO SHOW

for key,value in pairs (attributes) do
  
  if (in_array(value,best)) then
    hidequestion(key, false)
  end
end

Required Customizations

maxdiff - This is the MaxDiff question ID.

ids - This is a comma separated list of the ID for the questions or text elements that you wish to show/hide based on the MaxDiff best values. 

attributes - This is an array of the IDs for the questions or text elements that you wish to show/hide and the corresponding attribute value.