Tip: Check out the new looping function, a!forEach(). It does everything apply() does but with easier syntax, better null handling, and support for interface components.
apply( function, list, context )
Calls a rule or function for each item in a list, and provides any contexts specified.
See also:
Keyword | Type | Description |
---|---|---|
|
Rule or Function Reference |
Rule or expression function. |
|
Any Type Array |
List of elements that function iterates through. |
|
Any Type Array |
Variable number of parameters passed directly into each function evaluation. |
Any Type Array
Use fn!functionName
to reference an expression function and rule!ruleName
to reference a rule.
To use rules or functions that take more than one argument, use the merge()
function. For example, given a rule g(x, y), apply(rule!g, merge({a, b, c}, {d, e, f}))
returns {g(a, d), g(b, e), g(c, f)}
.
Null lists return a null list without executing the function.
The result of each operation is appended to each other in the same order as their corresponding item in the input list. If the result of each operation is an array, apply()
returns a two-dimensional array which can then be used for further computation. When the two-dimensional array is saved into a process variable, a node input or a custom data type, the array is flattened to a one-dimensional array. Local variables, however, can store the two-dimensional array without flattening it.
If you save the nested arrays into a process variable for multiple values, the nested function is flattened. Keep in mind that casting to a flattened array only happens when saving into a process variable, node input, custom data type, or custom data type field.
To avoid having the nested function flatten, you can use the output of the apply()
function as the input for a merge()
function.
apply()
cannot be used with rules or functions that store local data. This means any local variable that can be saved into, such as variables created using load()
or a!localVariables()
without using the "refreshAlways" configuration, cannot be created. Additionally, a!forEach()
and some components cannot be used. In these cases, apply()
will return an error. In these cases, use a!forEach()
or a!applyComponents()
instead of apply()
.
Given a function h(x, y)
, apply(fn!h, {a, b, c}, v)
returns {h(a, v), h(b, v) ,h(c, v)}
apply(fn!sum,{-1,2,3},2)
returns 1, 4, 5
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 | |
Process Reports | Incompatible | You cannot use this function to configure a process report. |
Process Events | Incompatible | You cannot use this function to configure a process event node, such as a start event or timer event. |
apply() Function