Introduction to scripting

Overview

Scripting in Discover provides advanced customization options. With custom code, you can pipe data and perform various operations in areas such as questions, error messages, and URLs.

JavaScript is the primary language used for creating custom logic in Discover. While you can execute any valid JavaScript code, Discover also offers a range of predefined functions and variables to simplify common tasks.

Injecting script

JavaScript can be injected into survey text to make the survey experience more dynamic. This is accomplished by wrapping the script to be executed in double curly braces: {{ and }}. These delimiters signal to the system that what they are wrapping should be executed as script and not written to the page as text.

Functions are case and spacing sensitive. If a capital or space in a function name or question is missed, the script will fail.

Example

The following example uses a predefined function.

Example showing the get label function. The script is {{ GetLabel(

When injected scripts are executed, the resulting value will replace the script in the survey text. In authoring a follow-up question, you could ask about the respondents response to the last question:

In the last question, you said {{ getLabel("Color Question") }} was your favorite. Tell us why it's your favorite color.

This would then return the following to the respondent:

In the last question, you said blue was your favorite. Tell us why it's your favorite color.

Comments

When writing custom scripts, it may be helpful to include comments. These are messages that can be used to describe what the script will perform. The comment will be ignored when the script is executed.

To insert a comment, wrap it inside /* and */ like this:

{{ RangeMax() /* This is my comment here */ }}