SurveyGizmo Script allows you to create complex logic and calculations from within your survey. It does require some knowledge of programming.
%%output is your output stream. It will display text & html directly to the survey canvas.
If you have suggestions on new functions please email them to support@sgizmo.com.
Script Functions
These are the bulk of the SurveyGizmo Scripting functions available to the script control
sgapiSubmitSurvey()
This function records the current survey as a 'partial'. It also records a snapshot of the survey information for immediate reporting
sgapiSubmitSurveyComplete()
This function submits the survey as a "Complete". All collected data in the survey is also submitted to reporting.
sgapiGetValue(%%ident)
This function gets the value of an answered question (or null, if not answered) and returns it.
sgapiCheckboxTotalChecked(%%ident)
This function returns the number of checkboxes selected for the given question.
sgapiGetScore(%%ident)
This function is identical to the function sgapiGetValue.
sgapiURLValue(%%name)
This function returns the value of a querystring variable passed into the survey where '%%name' is the name of the url variable.
sgapiResultsQuestionAverage(%%sku,%%query = "")
The first of the real-time reporting functions. This returns the average answer for the question sku given across all completed surveys in real time. %%query, allows you to optionally specify a query string variable to filter by. Like this: "fname=vanek" will return the average value for this question by people with the first name 'vanek'.
sgapiGetQuestionResponseCount(%%sku,%%osku = null)
This is also a real-time reporting function. It allows you to query the number of times a question has been answered. It's a count, not an average. By passing an "option sku" you can see how many times a question was answered a particular way. This function is very useful pro programing qouta limits! Helpful Tip: %%osku should be quoted out "%%osku" to avoid issues with an osku of zero.
sgapiGetQueryResponseCount(%%query)
This function returns the number of responses (completes) that have been collected for the current survey. It take an optional "%%query" parameter that filters by a query string variable.
sgapiSetValue(%%ident,%%value)
This function populates a response of a hidden, text or essay question. You can also use it set script content to write dynamic scripts!
sgapiSetTitle(%%ident,%%value,%%language = "English")
This function sets the title of a question or the text of a description area. HTML is allowed.
sgapiGetTitle(%%ident,%%language = "English")
This function returns the 'title' of a question.
sgapiSetHTMLEmail(%%ident,%%value,%%language = "English")
This function sets the content of an HTML email (auto-responder)
sgapiSetTEXTEmail(%%ident,%%value,%%language = "English")
This function sets the TEXT version of an auto-responder's body content.
sgapiGetQuestionOptionSelected(%%ident)
This function returns a zero-based index of the option selected for a RADIO, LIST, IMAGE_SELECT or MENU question. (If the question is randomized the index is based on the un-randomized version of that question)
sgapiHideQuestion(%%ident,%%hide)
This function hides or shows a question (the %%hide attribute is set to 'true' to hide and 'false' to show)
sgapiRemoveOption(%%ident,%%option)
The scripting way of doing Dynamic Show/Hide. This function removes (hides) a multiple choice option (by reporting value as %%option). For table questions it hides the column associated with that option for all rows.
sgapiSetRequired(%%ident,true/false)
This function toggles the "Required" status of a question.
sgapiAllQuestionsOfType(%%type,%%pagenumber = 1)
This function returns an array of all the questions (of a particular type) on a particular page.
sgapiTrimStr(%%value)
This function trims a string of trailing and preceding whitespace.
sgapiStrPos(%%haystack,%%needle,%%offset = 0)
This function returns the offset of a substring within a string.
sgapiSubStr(%%string,%%offset = 0,%%len = 255)
This function returns a substring of a string base don length and position
sgapiStrLen(%%string)
This function returns the length of a string
sgapiStr_replace(%%search,%%replace,%%subject)
This function looks for %%search inside of %%subject and overwrites %%search with %%replace
sgapiIsArray(%%string)
Returns 'true' if the variable is an array
sgapiCSVSplit(%%string)
Splits the given string into an array (comma seperated values)
sgapiCount(%%string)
Returns the number of elements in an array.
sgapiArraySet(%%array,%%index,%%string)
Sets the value of an item with an array (supports hash tables)
sgapiArrayGet(%%array,%%index)
Gets the value of an item in an array
sgapiJumpToPage(%%jumpto)
This function jumps the survey taker to the specified page.
sgapiDisqualify(%%message)
This function disqualified the user, ends the survey and displays a customized message to the user.
sgapiCreateLoopCount(%%increment)
This function creates an array of numbers (1 to 500) that can be used to power a loop.
sgapiStrtotime(%%string,%%time)
This function takes a string and converts it to a Unix timestamp, relative to the timestamp %%time. %%time is optional.
sgapiDate(%%format,%%time)
This function converts %%time a Unix timestamp into a human readable date and time. %%time is optional and defaults to the current time.
Example Script
This script example adds up all the checkboxes that are checked on the first and second pages of a survey.
If they choose 10 items then it submits the survey.
If they choose over 10 it disqualifies them (throws them out of the survey).
Less than ten and they are free to proceed to the current (next) page.
%%pagestocheck[] = 1;
%%pagestocheck[] = 2;
foreach(%%pagestocheck as %%page)
{
%%skus = sgapiAllQuestionsOfType("CHECKBOX",%%page);
foreach(%%skus as %%sku)
{
%%total += sgapiCheckboxTotalChecked(%%sku);
}
}
if(%%total == 10){
sgapiSubmitSurvey();
}
if(%%total > 10){
%%over = %%total - 10;
%%msg = "<h1>You have selected %%total nominees.<h1>";
%%msg .= "I'm sorry but that's <font color=red > %%over too many. </font></h1><br><br>Thanks for your time.</h1>";
sgapiDisqualify(%%msg);
}
else
{
%%output = "Thus far you have selected %%total nominees";
}