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:
choose()
.choose()
to determine the index.choose()
, index()
returns an item at a certain index within a list. Usually used for static lists instead of expressions.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.null
.choose()
does not evaluate all its arguments. First the key is evaluated, then the corresponding choice argument.choose
to avoid calling potentially costly expressions whose results would be discarded.When choosing values from a static list, the index() function is often easier to use. For example, both of the following examples will return the same output:
1
2
3
4
5
6
choose(
2,
"Low",
"Medium",
"High"
)
1
2
3
4
5
index(
{"Low", "Medium", "High"},
2,
"Unknown"
)
However, the example using index()
is far more common because the list of values can come from a single variable or constant rather than each value being provided in a separate argument. In addition, if an index value of 4 is provided in the examples above, choose()
returns an evaluation error, while index()
returns the default value Unknown.
Tip: One common use for the choose()
function is within a wizard pattern, since it can show each page in the wizard one at a time.
1
choose(2,2+2,4/2,3^2)
Returns 2
.
It can be useful to use the wherecontains()
function in conjunction with choose()
. Since wherecontains()
returns a list, use the first result for the key parameter.
1
2
3
4
5
6
7
8
9
a!localVariables(
local!rating: "Excellent",
choose(
wherecontains(local!rating, {"Poor","Satisfactory","Excellent"})[1],
mod(rand() * 10, 5),
mod(rand() * 10, 5) + 4,
10 - mod(rand() * 10, 2)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
a!localVariables(
local!selectionField: 2,
local!value: 2,
choose(
local!selectionField,
a!radioButtonField(
label: "Radio Button",
choiceLabels: {"One", "Two", "Three"},
choiceValues: {1, 2, 3},
value: local!value,
saveInto: local!value
),
a!checkboxField(
label: "Checkbox",
choiceLabels: {"One", "Two", "Three"},
choiceValues: {1, 2, 3},
value: local!value,
saveInto: local!value
),
a!dropdownField(
label: "Dropdown",
choiceLabels: {"One", "Two", "Three"},
choiceValues: {1, 2, 3},
value: local!value,
saveInto: local!value
)
)
)
In this example, the checkbox field is displayed since it is the second choice argument. In addition, the radio button and dropdown fields are not evaluated.
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