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

Function

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.

Parameters

Keyword Type Description

data

Any Type

A homogeneous array, whose indexed value is expected. Can also be a dictionary, map, CDT, or Record.

index

Any Type

The index or array of indices of the data. Index can be an integer, text, or a record type field reference.

default

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.

Returns

Any Type

Usage considerations

Default return values

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 index

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.

Examples

Retrieve a value at a single index

1
index({10, 20, 30}, 2, 1)

Returns 20.

Retrieve values at multiple indexes

1
index({10, 20, 30}, {1, 3}, 0)

Returns {10, 30}.

Retrieve values at repeated indexes

1
index({10, 20, 30}, {1, 1, 3}, 0)

Returns {10, 10, 30}.

Retrieve the value of a CDT field using the field name as the index argument

1
index(topaginginfo(1, 10), "startIndex", 0)

Returns 1.

Retrieve a value from a dictionary using the key as the index argument

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.

Retrieve the value of a map field using the field name as the index argument

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.

Retrieve the value of a record field using the record field reference as the index argument

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".

Return the value of a local variable field by name

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

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

index() Function

FEEDBACK