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.
- 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_ActionTable 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 = '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. - 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 Expression Type Constant Value 100
- 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 Expression Type Constant Value 100
- Click Save
Next we need to create a Business Object that will hold dynamic cases.
- From the left menu, select Data Management -> Busines Objects
Click on the New Business Object button. The New Business Object page appears.
Property Value Description Object Name ProductAction Use this name for the example. Template System -> Action Table
This template creates the required attributes to work with the Decision Rule. - Click Save.
- The detail page of this Business Object appear. Click on the Attributes tab.
Add the following Attributes:
Name Type CostBody TextArea CostType Integer PriceBody TextArea
- Deploy
- 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.
- 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 Expression Type Reference Table Table Name ProductAction
Predicate Condition Predicate - Type Attribute -> ConditionType Sort Id Sort - Type Ascending Cost CostBody Cost - Type Attribute -> CostType Price PriceBody Price - Type Type -> Constant - Click Save
- 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 Dog.
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 language javascript {"DATA":{"root_DecisionRule_Products":{"RETVAL":"1","COST":"100","PRICE":"100"}}}
- Next we need to populate some values into the ProductAction table and test it out. From the left menu, select Business Rules -> Rules
- Click on the Open Rule Generator button. The Rule Generator pop up shows up.
- Select Create object for the Type.
- Click Next
- Select the ProductAction for the Business Object.
- Checkbox the following Attributes and move them to the right: Condition, ConditionType, CostBody, CostType and PriceBody
- Click Finish
- Click on the Debug button in the toolbar next to the newly created rule. The Rule Debugger window pops up.
Enter the Parameter properties as follows:
Parameter Value Condition BEGIN :Result := 0; IF :ProductName = 'Watermelons' THEN :Result := 1; END IF; END;
ConditionType 3 CostBody 9 CostType 1 PriceBody 11 - Click Run
Change the Parameter properties as follows:
Parameter Value Condition BEGIN :Result := 0; IF :ProductName = 'Cat' THEN :Result := 1; END IF; END;
ConditionType 3 CostBody BEGIN
:Result := 60 * 0.75;END
;
CostType 3PriceBody 60 Click the Run button on the bottom left.
- After the rule was execute, close the Rule Debugger.
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.
- lick 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 Cat.
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 language javascript {"DATA":{"root_DecisionRule_Products":{"RETVAL":"1","COST":"45","PRICE":"60"}}}