Important Update to Custom Scripting
SurveyGizmo's Legacy Custom Scripting Language is being sunsetted in favor of the LUA programming language. See our new Lua Scripting Resources to get started using Lua in your Custom Script Actions.
For the foreseeable future, Custom Scripts using the Legacy Custom Scripting Language will continue to operate without issue; though it is a good idea to get started scripting with Lua. We will communicate sunset plans as they are formulated.
This is a realtime reporting function. You can query the total response count for a question using the %%questionID parameter. Or, by passing an option sku in %%osku, you can return the response count for a particular answer option. You can also filter by response status using the %%status parameter (Complete, Partial, Disqualified, Deleted).
|%%questionID||the ID of the question||true|
|%%osku||the sku of the option||false (defaults to null)|
|%%status||the status you wish to filter by ("Complete", "Partial", "Disqualified", "Deleted")||false (defaults to Complete)|
*Parameters must be specified in the above order.
Example 1: Get response count for a question
In this example we use this function to display the response count for question ID 2.
%%output .= "Response Count Overall Question: "; %%output .= "<br />"; %%output .= sgapiGetQuestionResponseCount(2);
The output would be: Response Count Overall Question:
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.
%%questionID = 2; %%osku=10001; %%output .= "Response Count First Answer Option (option sku 10001): "; %%output .= "<br />"; %%output .= sgapiGetQuestionResponseCount(%%questionID, "%%osku");
The output would be: Response Count 1st Option (option sku 10001): 9
Example 3: Get response count for a specified response status
If you wish to get the response count of a question and specifice the response status but have no option sku to specify the syntax is like so:
%%questionID = 2; %%osku = null; %%status = "Complete"; sgapiGetQuestionResponseCount(%%questionID,%%osku = null,%%status);
Example 4: Use sgapiGetQuestionResponseCount in combination with sgapiResultsQuestionTotal to compute an average
sgapiResultsQuestionTotal can also used in combination with sgapiResultsQuestionTotal() 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 = sgapiGetQuestionResponseCount(%%qID); %%people = sgapiResultsQuestionTotal(%%qID); %%guestsPerPerson = %%guests / %%people; %%output .= "Average Guests per Person: " . %%guestsPerPerson;