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.
executeAndGetOutput is the virtual method that executes a ruleset and return its outputs.
- Click Browse and select the java.util.Map type.
- Click Add and add the following two arguments:
Name Type rulesetName java.lang.String childInput java.util.Map
- In the BOM to XOM Mapping section, add the following code:
return RulesetChildRunner.execute(rulesetName, childInput).getOutputParameters();childInput is a variable typed java.util.Map that holds the child ruleset input parameters, and rulesetName is the child ruleset path.
- Verbalize the virtual method executeAndGetOutput and 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 childInput java.util.Map IN childRulesetPath java.lang.String IN_OUT result java.util.Map OUT
- 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 runner is the default verbalization of the RulesetChildRunner class, and result is a ruleset parameter that holds the output parameters of the child ruleset execution.
- Initialize your ruleset parameters either in the master ruleset rule flow or in your client
application that executes the master 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");
Parent topic: Cascading ruleset execution