Free cookie consent management tool by TermsFeed choose() Function
choose() Function

Tip:  Check out the new logical function, a!match(). It does everything choose() does but with additional flexibility so you can simplify your conditional logic without using an index.

Function

choose( key, choice1, choiceN )

Evaluates the choice argument at the given index and returns the result.

See also: wherecontains() and a!match()

Parameters

Keyword Type Description

key

Number (Integer)

The one-based index that selects which choice argument to evaluate and return.

choice1

Any Type

The first of n possible expressions, where n must be >= 1. Only the selected value is evaluated.

choiceN

Any Type

An unlimited number of expressions.

Returns

Any Type

Usage considerations

Working with nulls

  • If the selected choice evaluates to null, null will be returned.
  • The index parameter must be a scalar number between 1 and the number of choices. It cannot be null.

Evaluation order

Unlike most functions, choose does not evaluate all its arguments. First the index is evaluated, then the selected value arguments. The unchosen arguments are not evaluated. Use choose to avoid calling potentially costly expressions whose results would be discarded.

Examples

Use expressions as the choice arguments or as the index argument.

choose(2,2+2,4/2,3^2) returns 2

choose(weekday(today()),"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") returns the name of the day of the week

It can be useful to use the wherecontains function in conjunction with choose. Since wherecontains returns a list, use the first result for the index parameter.

1
2
3
4
5
6
	choose(
	  wherecontains(ri!rating, {"Poor","Satisfactory","Excellent"})[1],
	  mod(rand() * 10, 5),
	  mod(rand() * 10, 5) + 4,
	  10 - mod(rand() * 10, 2)
	)

Feature compatibility

The table below lists this function's compatibility with various features in Appian.
Feature Compatibility Note
Portals Compatible
Offline Mobile Compatible
Sync-Time Custom Record Fields Compatible

Can be used to create a custom record field that only evaluates at sync time.

Real-Time Custom Record Fields Incompatible

Custom record fields that evaluate in real time must be configured using one or more Custom Field functions.

Process Reports Compatible
Process Events Compatible

choose() Function

FEEDBACK