Scripting functions for survey elements

Introduction

These functions let you interact with survey elements such as questions. Common uses include:

  • Piping responses from previous questions into follow-up questions.
  • Referencing question settings such as required selections in error messages.
  • Keeping question text and logic in sync with how the survey is programmed.

Functions that require a question name as a parameter can be used anywhere in the survey. Functions that don't require a question name can only be used within the question they reference.

Some functions work across multiple question types but may return different results depending on the type. Make sure the function you use returns the expected value.

Available functions

This table shows which functions are available for each survey element.

Element Functions
Single-select getLabel
getValue
Multi-select getLabel
getValue
rangeMax
rangeMin
Open-end getValue
Single-select grid getLabel
getValue
Multi-select grid getLabel
getValue
rangeMax
rangeMin
Dropdown grid getLabel
getValue

constantSumTotal

This function uses the settings of the current question it is placed in.

Available for: constant sum

Function: constantSumTotal():number

Return: The value entered in the Total field.

decimalLimit

This function uses the settings of the current question it is placed in.

Available for: numeric

Function: decimalLimit():number

Return: The value entered in the Max decimal places field.

getLabel

This function returns the label(s) of the respondent's answer(s) to a given question. "Label" refers to the text of a list item — for example, “Red” or “Yellow.”

When multiple items are selected, the labels are automatically formatted into a natural, human-readable list (for example, using commas and “and”). These separators are also automatically translated based on the survey’s language tag, so no additional setup is required for multi-language surveys.

If the question has not been seen by the respondent, the function returns null.

Single-select

Function: getLabel(questionName: string): string | null

Example: {{getLabel("Q1")}}

Return: The text of the selected item, or an empty string ("") if unanswered, and null if the question was not seen.

Multi-select

Function: getLabel(questionName: string): string | null

Example: {{getLabel("Q1")}}

Return: A formatted string of the selected item labels:

  • 1 item: "Red"
  • 2 items: "Red and Yellow"
  • 3+ items: "Red, Orange, and Yellow"

or an empty string ("") if unanswered, and null if the question was not seen.

Single-select grid

Function: getLabel(questionName: string, rowNumber: number): string

Example: {{getLabel("Q1", 1)}}

Return: The text of the selected column for a given row, or an empty string ("") if unanswered, and null if the question was not seen.

Multi-select grid

Function: getLabel(questionName: string, rowNumber: number): string

Example: {{getLabel("Q1", 1)}}

Return: A formatted string of the selected columns for a given row:

  • 1 item: "Red"
  • 2 items: "Red and Yellow"
  • 3+ items: "Red, Orange, and Yellow"

or an empty string ("") if unanswered, and null if the question was not seen.

Dropdown grid

Function: getValue(questionName: string, rowNumber: number, columnNumber: number): string | null

Example: {{getValue("Q1", 1, 1)}}

Return: The text of the selected column for a given row, or an empty string ("") if unanswered, and null if the question was not seen.

Quota

Function: getLabel(quotaName: string): string | null

Example: {{getLabel("Quota1")}}

Return: A formatted string of the quota group name(s) the respondent was assigned to.

  • 1 group: "Group A"
  • 2 groups: "Group A and Group B"
  • 3+ groups: "Group A, Group B, and Group C"

or an empty string ("") if not assigned, and null if the quota was not seen.

getValue

This function returns the value of a respondent's answer. The meaning of “value” depends on the question type:

  • Open-end/numeric input: the text or number entered.
    Example: “My name is Skyler.”
  • Item number (single-select): the number of the selected item.
    Example: if “Red” is item 3 and is selected, the return value is 3.
  • Boolean (multi-select): whether the specified item was selected.
    Example: true if selected, false if not.
  • null: returned when the respondent did not see the question.

Single-select

Function: getValue(questionName: string): number | null

Example: {{getValue("Q1")}}

Return: The number of the selected item, or 0 if unanswered, and null if the question has not been seen.

Multi-select

Function: getValue(questionName: string, itemNumber: number): boolean | null

Example: {{getValue("Q1", 1)}}

Return: Whether the specified item was selected (true or false), or null if the question was not seen.

Open-end (single or multi-line)

Function: getValue(questionName: string): string | null

Example: {{getValue("Q1")}}

Return: The text entered by the respondent, or an empty string ("") if unanswered, and null if the question was not seen.

Single-select grid

Function: getValue(questionName: string, rowNumber: number): number | null

Example: {{getValue("Q1", 1)}}

Return: The number of the selected column for the specified row, or 0 if unanswered, and null if the question was not seen.

Multi-select grid

Function: getValue(questionName: string, rowNumber: number, columnNumber: number): boolean | null

Example: {{getValue("Q1", 1, 1)}}

Return: Whether the specified cell was selected (true or false), or null if the question was not seen.

Dropdown grid

Function: getValue(questionName: string, rowNumber: number, columnNumber: number): number | null

Example: {{getValue("Q1", 1, 1)}}

Return: The number of the selected column for the specified row, or 0 if unanswered, and null if the question has not been seen.

Numeric grid

Function: getValue(questionName: string, rowNumber: number, columnNumber: number): number | null

Example: {{getValue("Q1", 1, 1)}}

Return: The number entered in the specified cell, or 0 if unanswered, and null if the question was not seen.

Bipolar grid

Function: getValue(questionName: string, rowNumber: number): number | null

Example: {{getValue("Q1", 1)}}

Return: The number of the selected column for the specified row, or 0 if unanswered, and null if the question was not seen.

Constant sum

Function: getValue(questionName: string, itemNumber: number): number | null

Example: {{getValue("Q1", 1)}}

Return: The number entered for the specified item, or 0 if unanswered, and null if the question was not seen.

Numeric

Function: getValue(questionName: string): number | null

Example: {{getValue("Q1")}}

Return: The number entered by the respondent, or 0 if unanswered, and null if the question was not seen.

Quota

Function: getValue(quotaName: string): number | null

Example: {{getValue("Quota1")}}

Return: The index of the assigned quota group, or 0 if not assigned, and null if the quota was not seen.

Ranking

Function: getValue(questionName: string, itemNumber: number): number | null

Example: {{getValue("Q1", 1)}}

Return: The rank of the specified item, or 0 if unanswered, and null if the question has not been seen.

getListItemLabelOfRank

Available for: ranking

Function: getListItemLabelOfRank(questionName: string, Rank: number): string

Example: {{getListItemLabelOfRank("Priority Question", 1)}}

Return: The label of the item at the specified rank (for example, the item ranked 1st).

getListItemNumberOfRank

Available for: ranking

Function: getListItemNumberOfRank(questionName: string, Rank: number): number

Example: {{getListItemNumberOfRank("Priority Question", 1)}}

Return: The list item number of the item at the specified rank (for example, the item ranked 1st).

getMDBestLabel

This function uses the settings of the current MaxDiff question it is placed in.

Function: getMDBestLabel(): string

Return: The text entered in the Best label field.

getMDWorstLabel

This function uses the settings of the current MaxDiff question it is placed in.

Function: getMDWorstLabel(): string

Return: The text entered in the Worst label field.

getMDItemLabelOfRank

Available for: MaxDiff

Function: getMDItemLabelOfRank(exerciseName: string, rankNumber: number): string

Example: {{getMDItemLabelOfRank("Cookie MaxDiff", 1)}}

Return: The label of the item at the specified rank.

getMDItemNumberOfRank

Available for: MaxDiff

Function: getMDItemNumberOfRank(exerciseName: string, rankNumber: number): number

Example: {{getMDItemNumberOfRank("Cookie MaxDiff", 1)}}

Return: The item number at the specified rank.

rangeMax

This function uses the settings of the current question it is placed in.

Function: rangeMax(): number

Multi-select

Return: The value entered in the Maximum selections field.

Multi-select grid

Return: The value entered in the Max number of selections field (applies to each row).

Open-end (single and multi-line)

Return: The value entered in the Max characters field, or null if not set.

Numeric

Return: The value entered in the Max number field.

rangeMin

This function uses the settings of the current question it is placed in.

Function: rangeMin(): number | null

Multi-select

Return: The value entered in the Minimum selections field.

Multi-select grid

Return: The value entered in the Min number of selections field (applies to each row).

Open-end (single and multi-line)

Return: The value entered in the Min characters field.

Numeric

Return: The value entered in the Min number field.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript