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.
Do you need to perform basic math within a response? You can do so using our custom scripting. Because our scripting language is based on Lua any of the operators that are available in Lua are available in our scripting language, and thus, in our surveys! Learn more about Lua arithmetic operators.
Getting Started: Get Familiar with getvalue and setvalue
getvalue and setvalue are your friends when performing math in surveys; get familiar with these functions before you jump into doing math.
getvalue* returns the value (reporting value) of an answered question (or null, if not answered). Chances are when performing math in a survey, you'll want to pull one or more values from a question to use in your arithmetic. For single answer questions, a single value is returned. If you are looking to use the value from a more complex question this can get quite a bit trickier. Check out the getvalue function documentation to learn more.
*getvalue can be used to pull data from questions on previous pages only.
setvalue**populates the response value of the given question. Chances are when performing math in a survey, you'll want to use the result elsewhere in the survey; using setvalue you can store this data in a hidden value or other question for later use or reporting. The setvalue portion of the script below can be used to populate a hidden value, textbox, essay, radio button, drop-down menu, slider and image choice question. If you wish to populate other questions this can get quite a bit trickier. Check out the setvalue function documentation to learn more.
**setvalue can be used to set data in questions on any page.
Example
Let's say, for example, you want to multiply the number of shirts the customer orders (entered in a Textbox question in a survey) by the price so you can get a total amount due.
Add a survey with this script and setup to your account.
In the below script we pull the value of the number of shirts Textbox multiply it by the price and set the value of the Total Amount Due Textbox question.
numberofshirts = getvalue(5) --Get value of first textbox
shirtprice = 15 --Replace 15 with amount of shirt
totalamountdue = (numberofshirts * shirtprice) --Multiply the first textbox times the shirt amount
setvalue(6,totalamountdue) --Change 6 to ID of Hidden Value or Textbox
Another example of utilizing these functions would be creating a BMI (Body Mass Index) calculator.
Add a survey with this script and setup to your account.
weight = getvalue(2) --get value of first textbox
feet = getvalue(4) --get value of first dropdown
inches = getvalue(5) --get value of second dropdown
height = (feet * 12) + inches --multiply the first dropdown by 12 and add the value of the second dropdown
height_squared = height * height --multiply first textbox by its same value
bmi = (weight / height_squared) * 703 --divide the first textbox by height_squared and multiply by 703
bmi = round(bmi, 1) --rounds the bmi number to one decimal place
setvalue(6,bmi) --change 6 to ID of Hidden Value or Textbox
setvalue(8,bmi) --change 8 to ID of Hidden Value or Textbox