Defining the Rule: Decision Table

There are two ways you can define rules—either by using IF/THEN or by using Decision Tables. By using a Decision Table, you can create and use business rules in an easy-to-understand format that provides an alternative to the IF/THEN rule format, and it displays multiple related rules in a single spreadsheet-style view. In Rules Designer, a Decision Table presents a collection of related business rules with condition rows, rules, and actions, presented in a tabular form that is easy to understand.

You will use Decision Table for Check Customer rules and use if-then-else for DiscountCheck rules. For the Check Customer rule, you have following scenario :

  • First case, if the input Quote.customer type is New and Quantity is in the range of 0 to 10 , then Effective Discount will have a 10% increment and other values will be set as follows:

    If Quote.CustomerType == New and Quote.Quantity is between 0-10, then

    Set ApprovalFlow.CustomerType = True
    Set ApprovalFlow.newEffectiveDiscount = Quote. EffectiveDiscount+10
    Set ApprovalFlow..Number of Level for approval = 0
    Set ApprovalFlow.Tier1ApprovalNeeded = False
    Set ApprovalFlow.Tier2ApprovalNeeded = False
    
  • Second case, if the input, Quote.customer type is New and Quote.Quantity is in the range of 10 to 50 , then Effective Discount will have a 10% increment and other values will be set as follows:
    Set ApprovalFlow.CustomerType = True
    Set ApprovalFlow.newEffectiveDiscount = Quote. EffectiveDiscount+10
    Set ApprovalFlow..Number of Level for approval = 1
    Set ApprovalFlow.Tier1ApprovalNeeded = False
    Set ApprovalFlow.Tier2ApprovalNeeded = False
    
  • Third case, if the input, Quote.customer type is New and Quantity is greater than 50, Effective Discount will have a 15% increment and other values will be set as follows:

    If Quote.CustomerType == New and Quote.Quantity is between > 50, then

    Set ApprovalFlow.CustomerType = True
    Set ApprovalFlow .newEffectiveDiscount = Quote.EffectiveDiscount+15
    Set ApprovalFlow..Number of Level for approval = 2
    Set ApprovalFlow.Tier1ApprovalNeeded = False
    Set ApprovalFlow.Tier2ApprovalNeeded = True
    

How to do it...

In this section, you will define the Decision Table.

I. Define Condition

  1. Go to the Rule designer for CheckCustomer.rules and select Rulesets | Ruleset1.
  2. Click on Create Decision Table, to create a Decision Table for this ruleset.
    How to do it...
  3. Give the name CheckCustomer to the ruleset and enter NewCustomerQuantityCheckmatrix as name of the Decision Table:
    How to do it...
  4. Click the green plus(+) icon and select Condition to create a condition:
    How to do it...
  5. Click on<edit condition> and select Expression Builder.
  6. Select QuoteRequestType | Summary | customertype and click Insert Into Expression.
  7. Equate the expression with the CustomerType global which holds the value New.
    How to do it...
  8. Click OK.
  9. Click on the green plus (+) icon to add another condition to evaluate for quantity.
  10. Click Edit Condition.
  11. In the Value Option, select ProductItemType | quantity.
    How to do it...
  12. ProductitemType.quantityUnder this option, click on the Local List of Ranges pull-down menu, and select the Bucketset that you have created, QuantityBucket. The Conditions row requires a Bucketset from which to draw the values for each cell.
    How to do it...
  13. When finished, Save.

II. Define Rules

  1. Click the green plus (+) icon and select Rule, to create a condition.
  2. Click on the condition cell in the R1 Rule column for the Customer Type row and you can find a pop-up with the Boolean values.
  3. Check True so that the rule is executed if CustomerType = New is true, and actions associated in the column of this rule will also get executed.
    How to do it...
  4. Similarly, click on the empty tab in the R1 column for the Quantity row.
  5. Check the range 0-10. This means if along with CustomerType = New is True and the quantity falls in this range, the R1 rule will get activated, and actions specified in the condition tab for this R1 rule column will get executed.
    How to do it...
  6. Repeat the preceding steps to create a Decision Rules table, as follows:
    How to do it...
  7. When finished, Save.

III. Add Actions

  1. Click the green plus (+) icon and select Action | Assert new, to create actions.
  2. Click on Edit Actions, and this will open Action Editor.
  3. Chose ApprovalFlowType, and in Properties, check the properties you need. Let's take all of them.
    How to do it...
  4. Enter a value in each action cell, as shown in the following screenshot:
    How to do it...
  5. The values for the Actions cell newEffectiveDiscount are as follows:
    • R1: QuoteRequestType.summary.effectiveDiscount+10
    • R2: QuoteRequestType.summary.effectiveDiscount+10
    • R3: QuoteRequestType.summary.effectiveDiscount+15
    • R4: QuoteRequestType.summary.effectiveDiscount+10
  6. When you have finished this, Save.
  7. The final Rule designer with Rules, Conditions cell, and Actions cell entries, along with the pop-up conflicts, looks like the following screenshot:
    How to do it...

How it works...

At runtime, when facts match the Conditions cells, the Rules Engine prepares to run the actions associated with the rule.

Each condition row has a condition expression, and for each rule, a Condition cell. A condition expression is an expression that you build in Rules designer. The condition expression is often a fact property or a function result, but it can be any expression that has a type that can be associated with a Bucketset. Test expressions are often used. These expressions are associated with the built-in Bucketset.

Actions are associated with rules in a Decision Table. In an action, you can call a function, assert a new fact, retract a fact, or modify a fact. In the Actions area, the cells corresponding to an individual action for a rule are called Action cells. When you add multiple actions, the actions that you add in the Actions area are ordered; actions appearing in the higher rows run before actions in the following rows.

There's more...

Sometimes there may be conflicts in the rules in the Decision Table. Two rules conflict when they overlap and they have different actions. Two rules overlap when at least one of their condition cells has a bucket in common.

Rules designer finds conflicts and you can see the conflicts in the Conflict Resolution row in the Decision Table, when you click Show Conflicts. You can define conflict policy to handle and even resolve such conflicts.

Resolving Conflict

Conflict resolution is done as follows:

  1. Define a conflict policy in the Decision Table conflict policy, as follows:
    • Manual: Conflicts are resolved by manually specifying a conflict resolution for each conflicting rule.
    • Auto-override: Conflicts are resolved automatically using an override conflict
    • Resolution: When possible, solve conflicts using the Oracle Business rules' automatic conflict resolution policies
    • ignore: Conflicts are ignored
    Resolving Conflict

    You can find that a couple of conflicts are listed in the Conflict section in the Rule designer.

  2. Click R3 and select one of the conflict resolution methods.
  3. However, you will not follow any resolution, but will follow the strategy of Change the Decision Table to remove an overlap.
    Resolving Conflict
  4. Click Cancel in the Conflict Resolution dialog and change the Decision Table to remove overlap.
  5. Click the R3 condition cell, uncheck the [10..50] range, and keep>=50 checked.
    Resolving Conflict

    The Rule designer is created without conflict and with Conditions cell and Actions cell values.

    Resolving Conflict
  6. When finished, Save.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.242.175