Scripting in surveys

Learn more about the new scripting feature in surveys.

Note:
  • Scripting works with modern surveys only. It is not supported for classic surveys.
  • Alida Technical Support offers technical support and troubleshooting assistance for Alida-provided scripts. For self-authored scripts, it is up to the author to troubleshoot the script.
  • To add or edit scripts, you must be an admin.
Tip: Curious about scripting in modern surveys but don't know where to start? The Modern Survey Script Library in the Alida Help Center features copy/paste code snippets and step-by-step instructions for popular use cases.

What can scripting do?

Scripts run:
  • On the back end.

    There is no end user exposure, which makes them more secure and reliable than front-end scripting.

  • At the response stage.

    Scripts affect the data collected at response time. They do not affect data that was collected before scripts were added.

Note: Scripts on a page are ignored if the page does not have any visible question or step before the scripts run.

Use scripting to customize the collection and manipulation of response data. Currently, these data manipulation functions are possible:

  • Get response values from certain question types within a survey: answer values, selected or unselected values.
  • Perform arithmetic calculations.
  • Get or set values to questions within a survey.
  • Get or set values to profile variables and some system variables.
  • Get start and current time.
  • Show or hide questions.

    This is merely visual and does not mark the hidden question as skipped.

    Note: If all questions on a page are hidden, the entire page will be skipped. Respondents will proceed directly to the subsequent page.
  • Show or hide answers.
    Note:
    • If all answers in a question are hidden, the entire question will be hidden.
    • In Grid questions, if all rows or all columns are hidden, the entire question will be hidden.

These functions are coming in the near future:

  • Update text or images in questions or answers.

The data manipulation functions allow for many use cases. Here's an idea of the workflows that are possible with scripting:

  • Segment survey participants.

    Example

    Group participants into purchase intention, customer loyalty tier, or demographic categories based on their survey answers.

  • Recode choice data to numeric or scalar data.

    Example

    Assign numbers from 1 to 5 to a 5-point satisfaction scale.

  • Calculate age or duration values.

    Example
    • Calculate participants' ages using their Date of Birth responses.
    • Calculate how long participants spent on a particular survey page or survey.

Which question types are supported in scripting?

Data point manipulation is possible with the following question types.

Supported Not Supported
  • Single Choice
  • Multiple Choice
  • Net Promoter Score℠1
  • Single Choice Grid
  • Multiple Choice Grid
  • Allocation
  • Rank Order
  • Rating
  • Short Answer
  • Long Answer
  • Number
  • Date
  • Email
  • Zip / Postal Code
  • Phone Number
  • MaxDiff
  • Choice-Based Conjoint
  • Highlighter
  • Image Upload
  • Video Feedback
  • Appointment Booking

How does scripting work?

Scripts are authored in JavaScript and added to surveys at the page level. Scripts can run on survey pages in one of two ways:

  • On Load: The script runs when the page loads when piping, masking, and localization are already resolved.
  • On Complete: The script runs when the participant clicks Next and submits their response, before validation.

To see whether a survey page has a script applied while you are building the survey, look for a scripting icon in the Table of Contents beside the page.

To add a script, open the Page element for editing. Click the Scripting button.

In the Edit Scripts dialog, add the script on the On Load or On Complete tab. Click Save when you are done.

1 Net Promoter, NPS, and the NPS-related emoticons are registered U.S. trademarks, and Net Promoter Score and Net Promoter System are service marks, of Bain & Company, Inc., NICE Systems, Inc. and Fred Reichheld.