Lets you define local variables within a function and evaluate the expression with the new variables.
with( localVar1, …, [localVarN], expression)
localVar1: (Any Type) The local variable to use when evaluating the given expression and defined using
with(local!a,..., expression) or
with(local!a:10, ..., expression).
localVarN: (Any Type) Any additional local variables, as needed.
expression: (Any Type) The expression to evaluate using the local variables' values.
This function differs from the
load() function because it recalculates the local variable values when the expression is re-evaluated.
You cannot use this function within the Web Content Channel or a looping function or else an error occurs.
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 null value.
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.
See also: Grid Tutorial
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.
Using Local Variables
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
Using Local Variables with a Complex Value
with(local!a:getPersonForId(ri!id), local!a.firstName & " " & local!a.lastName) returns
Evaluating an Expression in the Context of a Process or Rule
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)
Overriding Variables with the Same Identifier
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
Defining a Local Variable by Referencing another Local Variable
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"