Important Update to Custom Scripting
The CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!
- 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. The exact date on this is to be determined; we will send notifications well ahead of time.
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).
Parameters* | Description | Required |
---|---|---|
%%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.
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.
%%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.
Check it out in an Example Survey
%%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;