Scripting functions for survey elements

Introduction

These functions let you interact with survey elements, such as questions.

You can use them to:

  • Pipe responses from previous questions into follow-up questions
  • Reference question settings (such as required selections) in error messages
  • Keep question text and logic in sync with how the survey is programmed

Functions that require parameters (such as a question name) can be used anywhere in the survey. Functions that do not 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
Numeric grid getValue
Bipolar grid getValue
Constant sum getValue
constantSumTotal
Numeric getValue
rangeMax
rangeMin
decimalLimit
Ranking getValue
getListItemLabelOfRank
getListItemNumberOfRank
MaxDiff getMDBestLabel
getMDWorstLabel
getMDItemLabelOfRank
getMDItemNumberOfRank
Quota getLabel
getValue

```

constantSumTotal

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

Available for: constant sum

FunctionconstantSumTotal():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

FunctiondecimalLimit():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. The term “label” refers to the text of an item in the list of items. For example, if a respondent selects “Red” and “Yellow,” the returned labels are “Red and 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

FunctiongetLabel(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

FunctiongetLabel(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

FunctiongetLabel(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

FunctiongetLabel(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.

Value may refer to:

  • Text/numeric input (open-end)
    Example: "My name is Skyler."
  • Item number (single-select)
    Example: If “Red” is item 3 and is selected, the return value is 3.
  • Boolean (multi-select)
    Example: Selected items return true; unselected items return false.
  • null
    Returned when the respondent did not see the question.

Single-select

FunctiongetValue(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

FunctiongetValue(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)

FunctiongetValue(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 war not seen.

Single-select grid

FunctiongetValue(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

FunctiongetValue(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

FunctiongetValue(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

FunctiongetValue(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

FunctiongetValue(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

FunctiongetValue(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

FunctiongetValue(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

FunctiongetValue(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

FunctiongetListItemLabelOfRank(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

FunctiongetListItemNumberOfRank(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.

Return: The text entered in the Best label field.

getMDWorstLabel

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

Return: The text entered in the Worst label field.

getMDItemLabelOfRank

Available for: MaxDiff

FunctiongetMDItemLabelOfRank(exerciseName: string, rankNumber: number): string

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

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

getMDItemNumberOfRank

Available for: MaxDiff

FunctiongetMDItemNumberOfRank(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.

FunctionrangeMax(): 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.

Multi-select

FunctionrangeMin(): number

Return: The value entered in the Minimum selections field.

Multi-select grid

FunctionrangeMin(): number

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

Open-end (single and multi-line)

FunctionrangeMin(): number | null

Return: The value entered in the Min characters field.

Numeric

FunctionrangeMin(): number

Return: The value entered in the Min number field.