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

  1. In the Rule Explorer view in Rule Designer, go to the boms folder in the rule project, and then double-click the RulesetChildRunner class.
  2. Create a virtual method:
    1. In the Members section in the BOM editor, click New.
    2. Select Method in the New Member window.
    3. Enter executeAndGetOutput in the Name field.

      executeAndGetOutput is the virtual method that executes a ruleset and return its outputs.

    4. Click Browse and select the java.util.Map type.
    5. Click Add and add the following two arguments:
      Name Type
      rulesetName java.lang.String
      childInput java.util.Map
  3. 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.

  4. Verbalize the virtual method executeAndGetOutput and the RulesetChildRunner class so that you can access them from a rule in Business Action Language (BAL).
  5. Create ruleset parameters:
    1. In the Rule Explorer view, right-click the rule project and select Properties.
    2. In the Properties window, select Ruleset Parameters in the left pane.
    3. 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
  6. 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.

  7. 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");