Introduction to scripting

Overview

Scripting in Discover enables advanced customization, allowing you to pipe data and execute operations in areas such as questions, error messages, and URLs.

JavaScript is the primary language for custom logic in Discover. While you can run any valid JavaScript code, Discover also provides predefined functions and variables to simplify common tasks.

Aside from dynamic scripts in survey text & messages, scripting is only available to users with active subscriptions.

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 */ }}