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.
This function returns the value (reporting value) of an answered question (or null, if not answered). For single answer questions, a single value is returned. Multi-answer questions return an array. Grid and custom group questions return a multidimensional array.
Parameters
Description
Required
questionID
the ID of the question
true
Examples
Single-Answer Questions
Many Alchemer questions collect and return a single answer when access via getvalue.
Questions with output that follow this pattern:
Radio Button
Dropdown Menu
Slider
Likert (Rating)
NPS
Textbox
Email
Number
Percent
Date
Essay
File Upload - Returns the file name as it is stored
Hidden Value
See the output for single-answer questions in an example survey.
This script prints the return to getvalue for single-select questions. The output will be the entered text for text fields or reporting value for the answer option.
print(getvalue(questionID))
This script prints the question title and the answer as a sentence.
print('The answer to question ' .. gettitle(questionID) .. ' is ' .. getvalue(questionID))
Multi-Answer Questions
There are a number of questions that collect a single vector of data. These questions all return an array. The option IDs are they keys and the answers are the values.
For example, the output from a Checkbox question looks like so:
Array ( [10005] => Bird [10006] => Other [10003] => Dog [10006-other] => iguana )
Questions with output that follow this pattern:
Checkboxes - the option IDs are the keys and the reporting values of the selected answers are the values
Textbox List - the option IDs are the keys and the answers to each textbox are the respondent's entries
Continuous Sum
Slider List
Drag and Drop Ranking - the option IDs are the keys and the respondent ranks are the values
Ranking Grid- the option IDs are the keys and the respondent-assigned ranks are the values
Open Card Sort
Image Select - the option IDs are the keys and the reporting values of the selected answers are the values
Cascading Dropdown Menu
Signature - returns an array that includes the signature as a base64 encoded image and the text entry name
See the output for multi-answer questions in an example survey.
This script prints the entire array for getvalue for multi-answer questions
print(getvalue(questionID))
This script prints the answers to a checkbox or image select question as a sentence.
print('The answers to '..(gettitle(questionID))..(' are: ')..(implode(',',getvalue(questionID))))
This script prints the answers to a textbox list, slider list, or continuous sum as multiple sentences.
questionID = 2
optiontitles = getquestionoptions(questionID)
if isanswered(questionID) then
for optionID,reportingvalue in pairs(getvalue(questionID)) do
print('The answer to question: ')
print(gettitle(questionID) .. ' ' ..optiontitles[optionID] .. ' is ' .. reportingvalue)
end
end
This script prints the ranks from a ranking type question
optiontitles = getquestionoptions(8)
for optionID,rank in pairs(getvalue(8)) do
if rank then
print('In question '..gettitle(8))
print(', option '..optiontitles[optionID]..' is ranked '..rank..'<br>')
end
end
You can also access individual answer options through the option ID.
Grid Questions, Custom Group and Contact Form Questions
For grid questions, custom group and contact form questions, the return is a multidimensional array. The row IDs are the keys and the value for each row is an array of the columnID and reporting value pairs for each selected/entered answer.
For example, the output from a Radio Button Grid looks like so:
See the output for grid and custom questions in an example survey.
This script iterates through the return for a radio button grid, semantic differential, or dropdown menu list question and prints the answer for each row as a sentence. The first for loop iterates through each row of a grid question.--The second for loop iterates through all of the answers for each row.
for rowid,rowarray in pairs(getvalue(questionID))do
for optionID,reportingvalue in pairs(rowarray) do
print('Question ' .. gettitle(questionID))
print(': The answer to row '.. gettitle(rowid)..' is '.. reportingvalue)
print('<br>')
end
end
This script iterates through the return for a textbox grid, dropdown menu grid, or star ranking grid and prints the answer for each field as a sentence. The first for loop iterates through each row of a grid question. The second for loop iterates through all of the answers for each row.
columntitles = getquestionoptions(questionID)
for rowid,rowarray in pairs(getvalue(questionID)) do
for optionID,reportingvalue in pairs(rowarray) do
print('Question: '..gettitle(questionID))
print(' Row: '..gettitle(rowid))
print(' Column: '..gettitle(rowid))
print(' Answer: '..reportingvalue..'<br>')
end
end
This script prints the results for each row of a checkbox grid question.
for rowid,rowarray in pairs(getvalue(questionID)) do
print('Question '.. gettitle(questionID)..': The answers to row '..gettitle(rowid)..' are '..implode(',',rowarray)..'
')
end
You can also get the answer to an individual cell of a grid question using the below script.
question = getvalue(questionID)
field = question[rowid][optionID]
Custom Tables
Custom Tables return a multidimensional array. The return includes an array per question/column; each table row has a key and the value entered/selected is the value.
MaxDiff questions return a multidimensional array. The below example output is for a MaxDiff question that shows 2 sets. The attributes array includes the attributes that were shown. Best and worst selections for each set are available via the best/worst keys.
Conjoint questions return a multidimensional array. The below example output is for a Conjoint question that shows 2 sets to the respondent with 4 cards each. The attributes array shows the keys and values for each attribute that was shown on the card. The score will vary based on the conjoint type; below the score of 100 indicates that the card was selected. If the card was a none card this will be included in the card array.
Net Promoter®, NPS®, NPS Prism®, and the NPS-related emoticons are registered trademarks of Bain & Company, Inc., Satmetrix Systems, Inc., and Fred Reichheld. Net Promoter Score℠ and Net Promoter System℠ are service marks of Bain & Company, Inc., Satmetrix Systems, Inc., and Fred Reichheld.