We'll create a simple decision rule that accepts a name of a product, and returns back it's cost and price.
- Open Application Studio of your solution
- From the left menu, select Business Rules -> Rules
- Click on New Rule. The New Rule page displays.
Enter the specific rule properties as follows. To read about the other properties, review the Rules help:
Property Value Description Rule Name DecisionRule_Products You can choose any meaningful name you like. Rule Usage Empty This rule usage provides the necessary input and output parameters necessary for a rule's purpose. Select the Empty Rule Usage for this example. Rule Type Decision This type of rule is meant will launch a special Decision Builder after you save the rule. - Click Save. The Rule's detail page is displayed.
- Click on the Parameters tab.
Click Add and create the following Parameters:
Name Type Default Behavior Length ProductName Text Input Cost Number Output Price Number Output Make sure to keep the Default and Length values empty.
- Click on the Decision Rules tab.
- Click on the New Rule button. A new case row appears.
- Click on the Edit button in the Predicate column of the new case. The Predicate Editor window pops up.
Enter the predicate properties as follows:
Property Value Description Expression Type SQL Non Query There 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. - Click Save
- Click on the Edit button in the Cost column of the case. The Condition Value Editor window pops up.
Enter the condition value properties as follows:
Property Value Description Expression Type Constant There 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. - Click Save
- Click on the Edit button in the Price column of the case. The Condition Value Editor window pops up.
Enter the condition value properties as follows:
Property Value Description Expression Type Constant There 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. - Click Save
Add three more cases with the following information:
Predicate
Expression TypePredicate
SQL BodyCost
Expression TypeCost
Value/SQL BodyPrice
Expression TypePrice
Value/SQL BodySQL 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;- For DEFAULT row set the Cost and Price to type Constant of value 0.
- Click on the General tab of the Decision Rule's detail page.
- Click on the Debug button in the toolbar. The Rule Debugger window pops up.
- In the Assign Values grid set the ProductName's value to Microwave.
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"}}}