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.
choose( key, choice1, choiceN )
Evaluates the choice
argument at the given index
and returns the result.
See also: wherecontains() and a!match()
Keyword | Type | Description |
---|---|---|
|
Number (Integer) |
The one-based index that selects which choice argument to evaluate and return. |
|
Any Type |
The first of n possible expressions, where n must be >= 1. Only the selected value is evaluated. |
|
Any Type |
An unlimited number of expressions. |
Any Type
null
will be returned.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.
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 | 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 | |
Process Reports | Compatible | |
Process Events | Compatible |
choose() Function