index( data, index, default )
Returns the data[index] if it is valid or else returns the default value.
See also: property(): This function acts as an alias to the index() function especially when applied over custom data types.
Keyword | Type | Description |
---|---|---|
|
Any Type |
A homogeneous array, whose indexed value is expected. Can also be a dictionary, map, CDT, or Record. |
|
Any Type |
The index or array of indices of the data. Index can be an integer, text, or a record type field reference. |
|
Any Type |
The default value to be returned if the data or the index is invalid, e.g. if the data itself is empty or the index is not found in the data. The type of the default value must be the same as that of the elements of the data. This parameter is optional. |
Any Type
The type of the default value must be same as that of the elements in the array. If it is not, a null value is returned if the index is not found.
When the data is a dictionary and the index is not found in the dictionary, then the default will be ignored and a null value will be returned. Consider using a map instead of a dictionary.
You cannot use index()
to specify the index for a saveInto
parameter. Instead, you will need to use square brackets to index into a saveInto parameter. See Interface Variables and Inputs to learn more.
1
index({10, 20, 30}, 2, 1)
Returns 20
.
1
index({10, 20, 30}, {1, 3}, 0)
Returns {10, 30}
.
1
index({10, 20, 30}, {1, 1, 3}, 0)
Returns {10, 10, 30}
.
1
index(topaginginfo(1, 10), "startIndex", 0)
Returns 1
.
The keys of dictionaries can be all numbers or all strings, so values in the index parameter must be specified as the same type.
In this example, the keys are numbers:
1
2
3
4
5
6
7
a!localVariables(
local!dictionary: {1: "abc", 2: 20},
{
index(local!dictionary, 1, null),
index(local!dictionary, "1", null)
}
)
Returns {"abc", null}
. The second instance's index is a string, so the default value is returned.
In this example, the keys are strings:
1
2
3
4
5
6
7
a!localVariables(
local!dictionary: { "1": "abc", "2": 20 },
{
index(local!dictionary, 1, null),
index(local!dictionary, "1", null)
}
)
Returns {null, "abc"}
. The first instance's index is a number, so the default value is returned.
If your dictionary keys are a mix of both numbers and strings, you must use a string as the index parameter:
1
2
3
4
5
6
7
8
a!localVariables(
local!dictionary: { 1: "abc", "2": 20 },
{
index(local!dictionary, 1, null),
index(local!dictionary, "1", null),
index(local!dictionary, "2", null)
}
)
Returns {null, "abc", 20}
. The first instance's index is a number, so the default value is returned.
The field names of maps are strings, so they must be specified as string values in the index parameter.
1
2
3
4
5
6
7
a!localVariables(
local!map: a!map(1: "abc", 2: 20),
{
index(local!map, 1, null),
index(local!map, "1", null)
}
)
Returns {"", "abc"}
. The first instance's index is a Number (Integer), so the default value is returned.
Note: Record type object references are specific to each environment. If you copy and paste these examples into your interface, they will not evaluate. Use them as a references only.
1
2
3
4
5
6
7
index(
recordType!Department(
recordType!Department.fields.name: "Engineering"
),
recordType!Department.fields.name,
""
)
Returns "Engineering"
.
To test this example, replace type!Person
with the person data type in your environment.
1
2
3
4
5
6
7
a!localVariables(
local!person: a!map(
firstName: "Jane",
lastName: "Doe"
),
index(local!person, "firstName", "")
)
Returns "Jane"
.
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 |
index() Function