Creating a new advanced XML condition
After creating the *.greex file, you can define an advanced XML condition or Greex rule.
- 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.
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, "WEB")</Expression>
<Expression>fn:equals(@orderQty, "100")</Expression>
</Group>
</Condition>
<Return>
<Value output="<Order TaxExemptFlag="N"/>"/>
</Return>
</If>
<Else>
<If>
<Condition name="TaxExempted?">
<Group op="and">
<Expression>fn:equals(@OriginalTotalAmount, "1000")</Expression>
<Expression>fn:intGreater(@orderLine,"5")</Expression>
</Group>
</Condition>
<Return>
<Value output="<Order discount="10"
TaxExemptFlag="Y"/>"/>
</Return>
</If>
<Else>
<Return>
<Value output="<Order discount="20"
TaxExemptFlag="N"/>"/>
</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.
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.
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.
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,
"WEB|STORE|CALLCENTER")</Expression>
<Expression>fn:equals(@orderLineQty, "200|500|250")</Expression>
</Group>
</Condition>
<Return>
<Value default="0" output="5|7|3"/>
</Return>
</If>
</GreexRule>