IFS

IFS returns the value that corresponds to the first logical expression that evaluates to TRUE.

IFS expects an even number of arguments.

Syntax

IFS(cond1, expr1, ... , condN, exprN)

Arguments

Description

cond1

Condition that evaluates to a truthy or a falsy value.

expr1

Expression that is evaluated only when corresponding condition returns a truthy value. Result is returned as a result of IFS expression.

condN

Nth condition.

exprN

Nth expression.

Examples

Example 1: Fetch surname attributes

In the following context we use MAP to walk through a list of users fetched from the context. Then we apply IFS to fetch the surname attribute from each of them. In the cases where a surname is not defined, we return a placeholder text.

{
"users": [
{
"name": "Jones",
"surname": "George"
},
{
"name": "Smith"
}
]
}

We will use the following expression:

MAP(IFS(_.surname <> NULL, _.surname, _.surname = NULL, 'Unknown surname'), users)

This returns the following collection:

["George", "Unknown surname"]

See also: MAP function.