Triggering a child ruleset execution from an action rule
The execution of a child ruleset can also be triggered from an action rule. Create a virtual method that executes a child ruleset and returns its output parameters. You then trigger an execution from your action rule.
Procedure
- In the Rule Explorer view in Rule Designer, go to the boms folder in the rule project, and then double-click the RulesetChildRunner class.
-
Create a virtual method:
- In the Members section in the BOM editor, click New.
- Select Method in the New Member window.
-
Enter executeAndGetOutput in the Name
field.
executeAndGetOutputis the virtual method that executes a ruleset and return its outputs. -
Click Browse and select the
java.util.Maptype. -
Click Add and add the following two arguments:
Name Type rulesetName java.lang.StringchildInput java.util.Map
-
In the BOM to XOM Mapping section, add the following code:
return RulesetChildRunner.execute(rulesetName, childInput).getOutputParameters();childInputis a variable typedjava.util.Mapthat holds the child ruleset input parameters, andrulesetNameis the child ruleset path. -
Verbalize the virtual method
executeAndGetOutputand the RulesetChildRunner class so that you can access them from a rule in Business Action Language (BAL). -
Create ruleset parameters:
- In the Rule Explorer view, right-click the rule project and select Properties.
- In the Properties window, select Ruleset Parameters in the left pane.
-
Click Add in the Ruleset Parameters pane, and then
create the following ruleset parameters:
Name Type Direction childInputjava.util.MapIN childRulesetPathjava.lang.StringIN_OUT resultjava.util.MapOUT
-
Trigger an execution of a child ruleset from your action rule.
Your action rule can look like the following text:
if <conditions> then set result to ruleset child runner.executeAndGetOuput ( childRulesetPath, childInput );
ruleset child runneris the default verbalization of the RulesetChildRunner class, andresultis a ruleset parameter that holds the output parameters of the child ruleset execution. -
Initialize your ruleset parameters either in the main ruleset rule flow or in your client
application that executes the main ruleset.
For example:
childInput = new HashMap(); childInput.put("param_name1", param_value1); childInput.put("param_name2", param_value2);To retrieve the child output parameters, add the following code:outputparam1 = result.get("outputparam1"); outputparam2 = result.get("outputparam2");