RuleAPI:Procedural commands/Var

From FlexRule Wiki
Jump to: navigation, search


This command can be used to evaluate all expressions (i.e., normal, monadic, functions, etc.). Or, when the name attribute is specified, it updates the parameter. For example, it assigns a value to a variable, which can be a simple primitive value such as an integer or a double type, or a computational formula, and (b) accepts nested addressing as the variable name in order to access other scope variables.

When name is not defined, it evaluates the entire expression that is defined in the value attribute. In this case, all the variables that are used in the expression must refer to defined parameters in the declaration section.


  1. name
    1. Description: Name of the target variable affected by the calculation or assignment, or alternatively the nested address. This name must be defined in the declaration section of the model.
    2. Mandatory: No
    3. Type: String
  2. ref
    1. Description: Reference to the variable name
    2. Mandatory: Yes (either value of ref is required)
    3. Type: String
  3. value
    1. Description: Contains the value or formula
    2. Mandatory: Yes (either value of ref is required)
    3. Type: String
  4. process
    1. Description: Defines whether the value is direct or it needs to be computed
    2. Mandatory: No (Default is True)
    3. Type: Boolean (true/false)
  5. source
    1. Description: If an extension exists for this variable assignment, it defines the source of the value on which the computation is based. For example, an XML source would be passed to the extension to calculate an XPath.
    2. Mandatory: No
    3. Type: String (name of another variable)
  6. path
    1. Description: Enables a set value, not insider properties, on the target object by referencing the properties using a dot or an element of array using brackets, such as [3] and [index] (index can be an integer variable defined in running context). When the variable you are referencing in name has got some inner properties and you want to target them to update, you can use this setting.
    2. Mandatory: No
    3. Type: String (referencing object property of array index)

Internal Commands


This command defines an extension point in the variable value assignment/calculation process. It must supply two parameters - assembly and handler - and the extension type must implement an interface named IExecutionExtension.


Sometimes, the value cannot be assigned with a setting attribute of value to the Var command, but it can be assigned with the Value command as an internal element.


Change an variable named 'age' value to '10'

  1. <Var name="age" value="10">


Change a property 'FirstName' of variable named 'person' value to 'Joe'

  1. <Var name="person" path="FirstName" value='"Joe"'>


  1. <Var name="Menswear">
  2.    <Value>
  3.      <![CDATA[
  4.       This is a multi line text!
  5.       Line 1
  6.       Line 2
  7.       Line 3
  8.    ]]>
  9.    </Value>
  10. </Var>


  1. <Var name="StarTotalPrice" value="(StarQty * StarPrice) - ((StarQty * StarPrice) * StarQtyDiscount)" />


In this case item must be defined in the declaration section of the model.

  1. <Var value="item.StarTotalPrice = (StarQty * StarPrice) - ((StarQty * StarPrice) * StarQtyDiscount)" />


  1. <Var name="StatementResult" source="xmlData" value="StatementAmount" process="true">
  2.    <!-- 
  3.      We want to handle the assignment inside our assembly
  4.      if in this case it is an xpath value.
  5.    -->
  6.    <Extension assembly="Sample.Advert.dll" handler="Sample.XPathValue"/>
  7. </Var>