Tip: Check out the new array function, a!update(). It does everything updatearray() does but with support for more data types like maps, CDTs, records, and dictionaries.
updatearray( array, index, value )
Inserts new values or modifies existing values at the specified index of a given array, and returns the resulting array.
See also:
Keyword | Type | Description |
---|---|---|
|
Any Type Array |
The array to modify. |
|
Integer or Integer Array |
The one-based index or array of indices at which to update the array. |
|
Any Type or Any Type Array |
The new value or values to add or replace existing values. |
Any Type Array
This function works with complex data types structures in the same way as simple structures. For example, assume you have a Case data type with a notes
field that represents a list of Notes. When an array of cases
is passed in as the input array, an array of cases returns. When an array of cases.notes
is passed in, an array of notes returns.
The index value must be greater than or equal to 1.
If the index is null, or an empty list, the input array is returned with no changes.
Common error messages and reasons are listed below:
Runtime error message | Reason |
---|---|
The list of indices and list of new values must be of equal length. The list of indices has <value> items. The list of new values has <value> items. |
Unless the new value is null, the list of indices must match the list of new values. |
Cannot cast from type <newValueType> to type <inputType> |
The type of the new value cannot be cast to the input array type. |
The indices are not of the expected type. Type of indices: <type passed in>. Type expected: <type expected>. |
The index is not a number (e.g., a list of nulls, or a string). |
An array is expected as the first parameter. |
The input array is a single value (not an array). For example: updatearray(1, 1, 200) returns an error. |
An invalid index is present (<index>). Indices must be greater or equal to one. |
The index is less than or equal to zero. For example: updatearray({1, 2, 3}, 0, 200) returns an error. |
updatearray({1, 2, 3}, 2, 200)
returns 1, 200, 3
updatearray({1, 2, 3}, {2, 3}, {200, 300})
returns 1, 200, 300
updatearray({1, 2, 3}, {2, 3}, 300)
returns 1, 300, 300
updatearray({1, 2, 3}, 2, "20")
returns 1, 20, 3
updatearray({1, 2, 3}, 5, 500)
returns 1, 2, 3, null, 500
updatearray({1, 2, 3}, {1, 5}, {100, 500})
returns 100, 2, 3, null, 500
updatearray({1, 2, 3}, 2, pv!Multiple[2])
returns 1, null, 3
where pv!Multiple[2]
has a null value
updatearray({1, 2, 3}, {2, 3}, pv!Multiple[2])
returns 1, null, null
where pv!Multiple[2]
has a null value
updatearray({1, 2, 3}, {4, 5}, pv!Multiple[2])
returns 1, 2, 3, null, null
where pv!Multiple[2]
has a null value
updatearray({tointeger(null)}, 2, 200)
returns null, 200
updatearray({}, {2, 3}, 3)
returns null, 3, 3
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 |
updatearray() Function