Check out the new evaluation function, a!localVariables(). It does everything with() does but with additional refresh options that may drastically improve the performance of your design.
with( localVar1, localVarN, expression )
Lets you define local variables within a function and evaluate the expression with the new variables.
See also: Grid Tutorial
The local variable to use when evaluating the given expression and defined using
Any additional local variables, as needed.
The expression to evaluate using the local variables' values.
In interfaces, this function differs from the
load() function because it recalculates the local variable values after interactions. This recalculation always happens, even if the interaction's updates could not have impacted the variable's value. This means data queries and other slow operations in
with() variables can have important performance impacts.
A local variable may be defined with or without a value, and the value may be simple or complex. When a value is not defined, it's assigned a
When you don't specify the
local! domain, the system first matches your variables with rules or constants with the same name, then looks for local variables with the name. Appian recommends that you always use the
local! domain when referring to local variables.
Local variables are not assigned a type. At runtime, the type of the variable will be based on the assigned value. For example, in
myvar is of type
The type returned by the
with() function will be that of the given expression.
A local variable may reference a previously defined local variable. They are evaluated in the given order.
The local variables are only available in the evaluation of the expression.
The expression can include other variables available in its context, such as process variables and rule inputs. For example,
with(local!myvar: 1, local!myvar + ri!myruleinput).
If an expression requires multiple evaluations of a complex value, you can use the
with() function to define the value as a local variable, so it's only evaluated once.
When a local variable uses the dot notation or brackets, a runtime error message will display. If the field name must contain special characters, enclose the name in single quotes.
You can copy and paste these examples into the Expression Rule Designer to see how this works.
with(local!a:10, local!b:20, local!a+local!b) returns
with(local!a:10, local!b:20, local!c:30, local!a+local!b+local!c) returns
with(local!a, isnull(local!a)) returns
with('local!a-name':10, local!b:20, 'local!a-name'+local!b) returns
with(local!a:getPersonForId(ri!id), local!a.firstName & " " & local!a.lastName) returns
When an expression is evaluated in the context of a process, the expression has access to all PV values for that process. Similarly, if the expression is used in a rule, the expression has access to all rule inputs.
with(local!a:pp!initiator, getDisplayName(local!a) & pv!b) returns
John Smith123 where (pv!b=123)
with(local!a:10, ri!a) returns
100 where (ri!a=100)
If the local variable has the same domain and name (domain + name combination) as another variable in the evaluation context, the local variable is used.
with(local!a:100, with(local!a:20, local!z:10, local!a+local!z)) returns
with(local!a:100, local!b:1, with(local!a:20, local!z:10, local!a+local!b+local!z)) returns
with(ri!a:10, 2*ri!a) returns
with(local!a:10, local!b:local!a*2, local!a+local!b) returns
with(local!a:10, with(local!b:local!a, local!c:20, local!a+local!b+local!c)) returns
with(local!a:local!b, local!b:10, local!a+local!b) returns
error because "a" references "b" which is not available to "a"