We'll create a simple decision rule that accepts a name of a product, and returns 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_ProductsYou 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 = 'Apples' 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:

    PropertyValueDescription
    Expression TypeConstantThere are three options available, we'll do a simple Constant and then later discuss the other options.
    Value

    10

    If the Predicate for this case was returned true, then the output parameter Cost will be set to 10.
  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:

    PropertyValueDescription
    Expression TypeConstantThere are three options available, we'll do a simple Constant and then later discuss the other options.
    Value

    15

    If the Predicate for this case was returned true, then the output parameter Price will be set to 15.
  18. Click Save
  19. Add three more cases with the following information:

    Predicate
    Expression Type
    Predicate
    SQL Body 
    Cost
    Expression Type 
    Cost
    Value/SQL Body 
    Price
    Expression Type 
    Price
    Value/SQL Body 
    SQL Non Query

     

    BEGIN
    :Result := 0;

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

     Constant 2 Constant 5
    SQL Non Query

    BEGIN
    :Result := 0;

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

     Constant 200 SQL Non Query

    BEGIN
    :Result := 200 * 1.25;
    END;

    SQL Non Query

    BEGIN
    :Result := 0;

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

    SQL Non Query

    BEGIN
    :Result := 800 * .75;
    END;

    SQL Non Query

    BEGIN
    :Result := 800 * 1.10;
    END;

  20. For DEFAULT row set the Cost and Price to type Constant of value 0.
  21. Click on the General tab of the Decision Rule's detail page.
  22. Click on the  Debug button in the toolbar. The Rule Debugger window pops up.
  23. In the Assign Values grid set the ProductName's value to Microwave.
  24. Click the Run button on the bottom left. Scroll down to the Rule Result text area and you should see the following result: 

    {"DATA":{"root_DecisionRule_Products":{"RETVAL":"1","COST":"200","PRICE":"250"}}}
  • No labels