FX DataGuide Expressions

Introduction

Expressions in the FX DataGuide Form Designer tool allow you to customize the flow, calculate variables, or automate the completion of FX DataGuide forms.

Prerequisites

To use the Form Designer, you need to:

Have these user licenses Have these permissions Complete these tasks
and review these topics
before continuing

Getting There

Expressions are part of the FX DataGuide Form Designer tool in the Admin Portal.

Expressions are fields available in a number of options in the Properties Panel, depending on the currently selected form element.

How it Works

You can build expressions to:

  • take responses to questions and calculate new values

  • and change the visibility of questions or pages in the form

  • automate form actions, such as automatically completing a form

Expressions can be built declaratively using the Build fields in the Properties Panel.

Use the Edit option for an Expression to manually write the expression.

Creating an Expression

When creating an Expression, you can build a new expression or edit an existing expression.

Using the Expression Build Tab

When adding a Form Logic Action (called a Trigger in the Logic section of the Form’s Properties Panel), you can use the Expression Builder to create the rule.

The Builder is limited to comparison actions on the responses to questions and adjusts the fields and options depending on the selected action.

For example, if a selected question does not allow a user to make multiple selections, then the "Any of" and "All of" rule options cannot be selected.

Using the Expression Edit Tab

The Expression Editor is a text field.

To use Expression functions, you must use the editor.

Consider beginning with the Expression Builder, then editing the results of the builder.

Functions

  • Expression functions follow a standard format:

    • functionName

    • ( )

      Any function, whether or not it accepts parameters, must be followed by an open and close parenthesis

    • ,

      For functions with parameters, each parameter is separated by a comma

Boolean Function Options

  • Examples of expressions where you desire to evaluate whether a condition is true or false.

    Expression Description

    " >= 21"

    Returns true if the question has a value of 21 or higher

    "( + + ) > 21 and == ‘yes’"

    Use or and and operators, squares and arithmetic operations

    "!( == ‘yes’ and ( + + ) > 21)"

    Use "!" or "not" to change the result on opposite

    "notempty"

    Returns true if name has a value

    empty

    Returns true if name has no value

    " = [‘English’, ‘Spanish’]"

    Returns true, if a user selects these two values in a question where these values are options. Typically used for checkbox question types.

    "contains ‘Spanish’"

    Returns true, if a user select 'Spanish' in checkbox. The user may or may not select other values in the question.

    age() >= 21

    Returns true, if function age returns 21 or greater. The function age is described below.

Matrix and Panel Questions

  • You can access values within a Panel of questions or a Matrix question type.

  • Use a "." to access child values

  • For matrix questions, use square brackets to indicate the position of the desired value, where the index begins at 0.

    For example to access the first value of a matrix, use {matrix[0].property}, where property is the desired value to return.

  • To access questions nested inside panels, use this format:
    {dynamicpanelname[index].questionname}

Function Types

You can use these functions when building an expression:

iif

Format

iif(condition: expression, valueIfTrue: any, valueIfFalse: any)

Result Type

Any

Description

Returns the value specified by valueIfTrue if the given condition is true and the value specified by valueIfFalse if the condition is false. The condition is an expression that can contain expression functions and references to question values (as question names in curly brackets).

Example

iif({question1} + {question2} > 20, 'high', 'low')

isContainerReady

Format

isContainerReady(nameOfPanelOrPage: string)

Result Type

Boolean

Description

Returns true, if all questions in the specified container (panel or page) are answered correctly (a respondent provided a valid input). This function recursively validates all questions in the container. If there is an error, the function returns false, otherwise true. In case a question’s value is empty and neither validators no required status are defined for the editor, validation would pass successfully.

Example

isContainerReady('page1')

isDisplayMode

Format

isDisplayMode()

Result Type

Boolean

Description

Returns true if a survey is in display mode.

Example

isDisplayMode()

currentDate

Format

currentDate()

Result Type

Date

Description

Returns the current date.

Example

currentDate()

today

Format

today(daysToAdd?: number)

Result Type

Date

Description

Returns the current date or a date calculated using an optional parameter. The parameter specifies the number of days to be added to the current date.

For example, "today()" returns the current date 0 hours, 0 minutes, "today(-1) returns yesterday’s date, "today(1)" returns tomorrow’s date, "today(2) returns day after tomorrow date, and so on.

Example

today() `
or
`today(2)

getDate

Format

getDate(questionName: expression)

Result Type

Date

Description

Returns the specified question’s date value.

Example

getDate({dateQuestionForBirthday})

age

Format

age(Date: any)

Result Type

Number

Description

Compares specified date value to current date and returns an age in years. The passed date value (which is typically taken from the referenced question) should be defined as a valid JavaScript Date.

Example

age({acquisitionDate})

diffDays

Format

diffDays(dateFrom: any, dateTo: any)

Result Type

Number

Description

Returns the number of days between two dates.
Dates are typically specified by expressions that correspond to questions (by their names in curly brackets) containing date values.

Example

diffDays({startDate}, {endDate}) < 7

sum

Format

sum(par1: number, par2: number, …​)

Result Type

Number

Description

Returns the sum of the passed arguments.

Example

sum({total1}, {total2})

max

Format

max(par1: number, par2: number, …​)

Result Type

Number

Description

Returns the largest value from a list of the passed arguments.

Example

max({total1}, {total2})

min

Format

min(par1: number, par2: number, …​)

Result Type

Number

Description

Returns the largest value from a list of the passed arguments.

Example

min({total1}, {total2})

avg

Format

avg(par1: number, par2: number, …​)

Result Type

Number

Description

Returns the average value of the passed arguments.

Example

avg({total1}, {total2}, {total3})

sumInArray

Format

sumInArray(questionName: expression, propertyName: string)

Result Type

Number

Description

Returns the sum of values in a array taken from the specified question property (both - the question and its property - are referenced by their names).

Example

sumInArray({matrixdynamic1}, 'total') > 1000

maxInArray

Format

maxInArray(questionName: expression, propertyName: string)

Result Type

Number

Description

Returns the maximum of all values in an array specified by a property (propertyName) of a matrix question (questionName specified as the question name in curly brackets).

Example

maxInArray({matrixdynamic4}, 'quantity') > 20

minInArray

Format

minInArray(questionName: expression, propertyName: string)

Result Type

Number

Description

Returns the minimum of all values in an array referenced by a property (propertyName) of a matrix question (questionName specified as question name in curly brackets).

Example

minInArray({matrixdynamic3}, 'quantity') > 5

avgInArray

Format

avgInArray(questionName: expression, propertyName: string)

Result Type

Number

Description

Returns the average of all values in an array referenced by a property (propertyName) of a matrix question (questionName specified as question name in curly brackets).

Example

avgInArray({matrixdynamic2}, 'quantity') > 10

countInArray

Format

countInArray(questionName: expression, propertyName: string)

Result Type

Number

Description

Returns the total number of items in an array referenced by a property (propertyName) of a matrix question (questionName specified as the question name in curly brackets).

Example

countInArray({matrixdynamic5}) > 10