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 function returns the response count for the given question ID from all responses that have been processed. The response count that is returned will not include data from any responses that haven't been processed; this includes the current response when the script is run.

You can query the total response count for a question using the questionID parameter. Or, pass an optionID to return the response count for a particular answer option. You can also filter by response status using the status parameter.

See this function in action in an example survey.
Parameters*
Description
Required
Possible Values
questionID
the ID of the question
true
optionID
the ID of the option
false (defaults to null)
status
the status you wish to filter by
false (defaults to Complete)"Complete" "Partial" "Disqualified" "Deleted"

*Provide parameters in the above order.

Examples

Example 1: Get response count for a question

In this example, we use this function to display the response count for question ID 2.

print(getquestionresponseCount(2))

Example 2: Get response count for a question option

We can also use this function to display the response count for the first answer option for question ID 2.

option=10001
print(getquestionresponsecount(2,option))

Example 3: Get response count for a specified response status

If you wish to get the response count of a question and specify the response status but have no optionID to specify the syntax is like so:

questionID = 2
optionID = ''
status = "Complete"

getquestionresponsecount(questionID,optionID,status)

Example 4: Use getquestionresponsecount in  combination with resultsquestiontotal to compute an average

getquestionresponsecount can also be used in combination with resultsquestiontotal to calculate an average. For example, if question ID 2 asks for the number of guests you will be bringing to the party, then we can calculate how many guests each person is bringing on average.

qID = 2

guests = getquestionresponsecount(qID)
people = resultsquestiontotal(qID)
guestsPerPerson = guests / people