Use the following functions to reference and define variables and functions within expressions.
References the value of a variable. The variable can either be an external variable supported by the host application or an internal variable defined with <defvar>.
<defvar name=’milk’><s>milkvalue</s></defvar> <defvar name=’shake’><s>milk</s></defvar> <ref><ref>shake</ref>
evaluates to <s>milkshake</s>
Defines a new variable. The variable can then be referenced by any expression within and below the containing expression in which the variable was defined. The variable must be given a name using the XML attribute name.
A defvar statement should not reference itself. If it does, it will cause a loop.
Avoid the following constructions.
<defvar name=’fullname’> <ref>fullname</ref> </defvar>
<defvar name=’counter’/> <add><ref>counter</ref> <i>0</i> </add> </defvar>
The following expression defines a variable and initializes its value to a list of two elements.
<defvar name=’theList’> <list> <s>apples</s> <s>oranges</s> </list> </defvar>
The following expression defines a variable and initializes its value to the integer zero.
<defvar name=’counter’> <i>0</i> </defvar>
Defines an argument within a function defined with <defun>. Arguments are similar to variables, but they must be defined in the order in which arguments are passed to the function.
<defarg name=’arg1’/> <defarg name=’arg2’/>
Defines a new function. The <defarg> function must be used to declare the arguments to a function. Use the <call> function to execute the function. Functions are typically defined within forms.
<defun name=’add100’> <defarg name=’input’/> <add> <ref>input</ref> <i>100</i> </add> </defun>
Calls a user-defined function. The arguments to call are assigned to arguments with <defarg> in the so-called function. The order of the call arguments must match the order of the <defarg>s. In previous releases, the call function could be used to call rules. Now, use the rule function for that purpose.
The following expression returns 142.
<call name=’add100’> <i>42</i> </call>
Calls a rule. The arguments to rule are passed by name using the argument element. The value of an argument can be specified with the value attribute if it is a simple string. The argument value can also be calculated with an expression by omitting the value attribute and instead writing an expression within the body of the argument element.
A <rule> element can also call another rule that dynamically calculate the name of another rule to call.
For more information on creating or calling rules in forms and workflows, see the chapter titled Rules.
The following expression returns the employee ID of the designated user.
<rule name=’getEmployeeId’> <argument name=’accountId’ value=’maurelius’/> </rule> <rule name=’getEmployeeId’> <argument name=’accountId’> <ref>username</ref> </argument> </rule>
The following expression calls another rule that calculates the returned value.
<rule> <cond> <eq><ref>var2</ref><s>specialCase</s></eq> <s>Rule2</s> <s>Rule1</s> </cond> <argument name=’arg1’> <ref>variable</ref> </argument> </rule>