Introduction to scripting

Overview

Scripting in Discover enables advanced customization, letting you pipe data and execute operations in questions, error messages, and URLs. JavaScript is the primary language for custom logic, and 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 paid subscriptions.

Injecting script

Inject JavaScript into survey text by wrapping it in double curly braces: {{ and }}. These delimiters tell the system to execute the content as script rather than display it as text.

Note: functions are case and spacing sensitive. A missed capital letter or space in a function name or question reference will cause the script to fail.

Example

The following example uses a predefined function. When a script is executed, its resulting value replaces the script in the survey text. For example, this follow-up question:

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

Would display to the respondent as:

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

Comments

Include comments in custom scripts to describe what the script does. Comments are ignored when the script executes. Wrap comments in /* and */ .

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