FunctionCopy link to clipboard
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.
ParametersCopy link to clipboard
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. |
ReturnsCopy link to clipboard
Any Type
Usage considerationsCopy link to clipboard
Default return valuesCopy link to clipboard
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.
Limitations on saving to an array indexCopy link to clipboard
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.
ExamplesCopy link to clipboard
Retrieve a value at a single indexCopy link to clipboard
1
index({10, 20, 30}, 2, 1)
Copy
Returns 20
.
Retrieve values at multiple indexesCopy link to clipboard
1
index({10, 20, 30}, {1, 3}, 0)
Copy
Returns {10, 30}
.
Retrieve values at repeated indexesCopy link to clipboard
1
index({10, 20, 30}, {1, 1, 3}, 0)
Copy
Returns {10, 10, 30}
.
Retrieve the value of a CDT field using the field name as the index argumentCopy link to clipboard
1
index(topaginginfo(1, 10), "startIndex", 0)
Copy
Returns 1
.
Retrieve a value from a dictionary using the key as the index argumentCopy link to clipboard
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)
}
)
Copy
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)
}
)
Copy
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)
}
)
Copy
Returns {null, "abc", 20}
. The first instance's index is a number, so the default value is returned.
Retrieve the value of a map field using the field name as the index argumentCopy link to clipboard
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)
}
)
Copy
Returns {"", "abc"}
. The first instance's index is a Number (Integer), so the default value is returned.
Retrieve the value of a record field using the record field reference as the index argumentCopy link to clipboard
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 reference only.
1
2
3
4
5
6
7
index(
recordType!Department(
recordType!Department.fields.name: "Engineering"
),
recordType!Department.fields.name,
""
)
Copy
Returns "Engineering"
.
Return the value of a local variable field by nameCopy link to clipboard
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", "")
)
Copy
Returns "Jane"
.
Feature compatibilityCopy link to clipboard
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 | |
Process Autoscaling | Compatible |