Creating a new advanced XML condition

After creating the *.greex file, you can define an advanced XML condition or Greex rule.

You can create two types of advanced XML conditions:
  • Normal advanced XML condition
  • Decision Table based advanced XML condition.

Normal advanced XML condition

After creating the *.greex file, you can define a normal advanced XML condition or Greex rule.

Note: Make sure that you do not add any comments in the advanced XML condition or Greex rule of any type.

The normal advanced XML condition is useful in scenarios where you need to define multiple condition criteria for an advanced XML condition you need to define multiple condition criteria and each condition criteria is associated with different attributes. These multiple condition criteria are defined using nested IF and ELSE constructs. For example, you may want to create a normal advanced XML condition for the condition criteria such as:

If Ordertype="WEB" and OrderQty="100", then TaxExemptFlag="N". 
Else
   If OriginalTotalAmount="1000" and OrderLine>"5", then
      discount="10" TaxExemptFlag="Y".
   Else TaxExemptFlag="N".

In this case, we have multiple condition criteria and each condition criteria has different attributes associated with it. The first condition criteria has Ordertype, OrderQty, and Discount associated with it. Whereas, the second condition criteria has OriginalTotalAmount, OrderLine, and TaxExemptFlag associated with it.

These condition criteria are defined in the *.greex file using nested IF AND ELSE constructs. A sample *.greex file for the advanced XML condition is as follows:

<GreexRule desc="Determine Discount and Tax Exemption based on 
                 various attributes" 
         id="getDiscountTaxExempt" 
         name="Get Discount and Tax Exempt" 
         returnType="Xml" 
         type=""> 
<If> 
   <Condition name="isDiscount20?"> 
     <Group op="and"> 
       <Expression>fn:equals(@orderType, &quot;WEB&quot;)</Expression>       
       <Expression>fn:equals(@orderQty, &quot;100&quot;)</Expression> 
     </Group> 
   </Condition> 
   <Return> 
     <Value output="&lt;Order TaxExemptFlag=&quot;N&quot;/>"/> 
   </Return> 
</If> 
<Else> 
  <If> 
    <Condition name="TaxExempted?"> 
     <Group op="and"> 
       <Expression>fn:equals(@OriginalTotalAmount, &quot;1000&quot;)</Expression> 
       <Expression>fn:intGreater(@orderLine,&quot;5&quot;)</Expression> 
     </Group> 
    </Condition> 
    <Return> 
       <Value output="&lt;Order discount=&quot;10&quot;            
                      TaxExemptFlag=&quot;Y&quot;/>"/> 
    </Return> 
   </If> 
<Else> 
   <Return> 
     <Value output="&lt;Order discount=&quot;20&quot;  
                    TaxExemptFlag=&quot;N&quot;/>"/> 
   </Return> 
</Else> 
</Else> 
</GreexRule>

Decision table based advanced XML condition

After creating the *.greex file, you can define a normal advanced XML condition or Greex rule.

Note: Make sure that you do not add any comments in the advanced XML condition or Greex rule of any type.

Decision table based advanced XML conditions are useful in scenarios where you have multiple nested condition criteria to be defined for an advanced XML condition but each condition criteria has same attributes associated with it. In such cases, you can write just one condition and have a table of parameters that works like a switch statement. In the decision table based advanced XML condition you can define multiple nested condition criteria in a single IF construct. Hence, there is no ELSE construct in case of decision table based advanced XML conditions. The IF construct contains an array of constant values instead of one constant value as used to be in case of normal advanced XML conditions. The IF construct has a table of parameters that works like a switch statement.

For example, you may want to create a decision table based advanced XML condition for the condition criteria such as:
If Ordertype="WEB" and OrderLineQty="200", then Discount="5". 
Else 
   If Ordertype="STORE" and OrderLineQty="500", then  Discount="7" 
Else  
  If Ordertype="CALL" and OrderLineQty="250", then Discount="3". 
  Else 
   default="0"

The following decision table describes the previous scenario:

Order Type

Order Line Quantity

Discount

WEB

200

5

STORE

500

7

CALLCENTER

250

3

default 0

In this case, we have multiple condition criteria but each condition criteria has the same attributes associated with it. All the condition cases have Ordertype, OrderLineQty, and Discount attributes associated with it. Therefore, this advanced XML condition has only one IF construct and it contains an array of constant values.

Note: For a decision table based Greex rule, it is mandatory to give a default return value. This value is returned if no IF condition gets satisfied.

These condition criteria are defined in the *.greex file using IF constructs. A sample *.greex file for the decision table-based advanced XML condition is as follows:

<GreexRule desc="Determine Discount based on some attributes"
           id="getDiscount"
           name="Get Discount"
           returnType="String"
           type="DecisionTable">>
 <If>
   <Condition name="isDiscount5?">
     <Group op="and">
       <Expression>fn:equals(@orderType, 
                  &quot;WEB|STORE|CALLCENTER&quot;)</Expression>
       <Expression>fn:equals(@orderLineQty, &quot;200|500|250&quot;)</Expression>
     </Group>
   </Condition>
   <Return>
      <Value default="0" output="5|7|3"/>
    </Return>
 </If> 
</GreexRule>