Local variables are created as part of an expression or an expression block and cannot be accessed from outside of it. However, from within an expression you can refer to any variable that exists in the scope of the expression and its parent scopes.
def String upperVar := "1"; begin def String lowerVar := "2"; upperVar := "3"; end; //this is not correct: //lowerVar := "4";
To create a local variable use the def
keyword in an expression. Note that def
only declares the variable:
Note: If you need to use whitespaces in a name, wrap the name in single quotes:
def Integer 'variable name with spaces';'variable name with spaces' := 34;However, mind that using whitespaces in names is strongly discouraged.
The variable value when declared is null
, which is returned as its value.
To assign a value to a variable, use the assignment (:=
) operator: such an expression returns the right-hand-side value of the assignment.
You can set an expression variable as final (once initialized, final variables cannot have their value changed):
Note: In models, you can define also global and local variables. Global variables are accessible from the entire Model; local variables within the given resource, such as, a process or form. Mind you cannot create global or local variables in the Expression Language; these are created in dedicated model resources.