Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

We'll create a more complex decision rule that uses a combination of static cases and dynamic ones through action tables. This rule will accept a product name, and return back it's cost and price. 

  1. Open Application Studio of your solution
  2. From the left menu, select Business Rules -> Rules
  3. Click on New Rule. The New Rule page displays.
  4. Enter the specific rule properties as follows. To read about the other properties, review the Rules help:

    PropertyValueDescription
    Rule NameDecisionRule_ActionTableYou can choose any meaningful name you like.
    Rule UsageEmptyThis rule usage provides the necessary input and output parameters necessary for a rule's purpose. Select the Empty Rule Usage for this example.
    Rule TypeDecisionThis type of rule is meant will launch a special Decision Builder after you save the rule.
  5. Click Save. The Rule's detail page is displayed.
  6. Click on the Parameters tab.
  7. Click Add and create the following Parameters:

    NameTypeDefaultBehaviorLength
    ProductNameText Input 
    CostNumber Output 
    PriceNumber Output 

     Make sure to keep the Default and Length values empty.

  8. Click on the Decision Rules tab.
  9. Click on the New Rule button. A new case row appears.
  10. Click on the Edit button in the Predicate column of the new case. The Predicate Editor window pops up.
  11. Enter the predicate properties as follows:

    PropertyValueDescription
    Expression TypeSQL Non QueryThere are three options available, we'll do SQL Non Query for this example and then later discuss the other options.
    SQL Body

    BEGIN
    :Result := 0;

    IF :ProductName = 'Dog' THEN
    :Result := 1;
    END IF;
    END;

    In this Predicate we check if ProductName is Apples, if it is then we set the system parameter Result to 1 indicating that this is the case we want to evaluate.
  12. Click Save
  13. Click on the Edit button in the Cost column of the case. The Condition Value Editor window pops up.
  14. Enter the condition value properties as follows:

    PropertyValue
    Expression TypeConstant
    Value

    100

  15. Click Save
  16. Click on the Edit button in the Price column of the case. The Condition Value Editor window pops up.
  17. Enter the condition value properties as follows:

    PropertyValue
    Expression TypeConstant
    Value

    100

  18. Click Save
  19. Next we need to create a Business Object that will hold dynamic cases.


    1. From the left menu, select Data Management -> Busines Objects
    2. Click on the New Business Object button. The New Business Object page appears.

      PropertyValueDescription
      Object NameProductActionUse this name for the example.
      Template

      System -> Action Table

      This template creates the required attributes to work with the Decision Rule.
    3. Click Save.
    4. The detail page of this Business Object appear. Click on the Attributes tab.
    5. Add the following Attributes:

      NameType
      CostBodyTextArea
      CostTypeInteger
      PriceBodyTextArea
  20. Deploy
  21. Go back to the detail page of the Decision Rule, if you didn't close anything it would be the tab named Rule - DecisionRule_ActionTable on the top of the screen.
  22. Click on the New Rule button. A new case row appears.
  23. Click on the Edit button in the Predicate column of the new case. The Predicate Editor window pops up.
  24. Enter the predicate properties as follows:

    PropertyValue
    Expression TypeReference Table
    Table Name

    ProductAction

    PredicateCondition
    Predicate - TypeAttribute -> ConditionType
    SortId
    Sort - TypeAscending
    CostCostBody
    Cost - TypeAttribute -> CostType
    PricePriceBody
    Price - TypeType -> Constant
  25. Click Save
  26. Click on the General tab of the Decision Rule's detail page.
  27. Click on the Debug button in the toolbar. The Rule Debugger window pops up.
  28. In the Assign Values grid set the ProductName's value to Dog.
  29. Click the Run button on the bottom left. Scroll down to the Rule Result text area and you should see the following result: 

    Code Block
    languagejavascript
    {"DATA":{"root_DecisionRule_Products":{"RETVAL":"1","COST":"100","PRICE":"100"}}}
  30. Next we need to populate some values into the ProductAction table and test it out. From the left menu, select Business Rules -> Rules
  31. Click on the Open Rule Generator button. The Rule Generator pop up shows up.
  32. Select Create object for the Type.
  33. Click Next
  34. Select the ProductAction for the Business Object.
  35. Checkbox the following Attributes and move them to the right: Condition, ConditionType, CostBody, CostType and PriceBody
  36. Click Finish
  37. Click on the Debug button in the toolbar next to the newly created rule. The Rule Debugger window pops up.
  38. Enter the Parameter properties as follows:

    ParameterValue
    Condition

    BEGIN :Result := 0; IF :ProductName = 'Watermelons' THEN :Result := 1; END IF; END;

    ConditionType3
    CostBody9
    CostType1
    PriceBody11
  39. Click Run
  40. Change the Parameter properties as follows:

    ParameterValue
    Condition

    BEGIN :Result := 0; IF :ProductName = 'Cat' THEN :Result := 1; END IF; END;

    ConditionType3
    CostBodyBEGIN :Result := 60 * 0.75; END;
    CostType
    3
    PriceBody60
  41. Click the Run button on the bottom left.

  42. After the rule was execute, close the Rule Debugger.
  43. Go back to the detail page of the Decision Rule, if you didn't close anything it would be the tab named Rule - DecisionRule_ActionTable on the top of the screen.

  44. lick on the General tab of the Decision Rule's detail page.
  45. Click on the Debug button in the toolbar. The Rule Debugger window pops up.
  46. In the Assign Values grid set the ProductName's value to Cat.
  47. Click the Run button on the bottom left. Scroll down to the Rule Result text area and you should see the following result: 

    Code Block
    languagejavascript
    {"DATA":{"root_DecisionRule_Products":{"RETVAL":"1","COST":"45","PRICE":"60"}}}