Skip to main content
Version: 10.2.9

Add composite rules

Composite rules define a Business Process (BP) flow variant, depending on the Record column values.

For the example in the figure below, the composite rule can be interpreted as follows: if the website_status value of a record is VALID, execute the Rename the Company Contact Information task for the record; otherwise, go to End.

Create composite rule

You can add a composite rule to a BP on the Workflow tab using one of the following methods:

  • Drag from the toolbar or choose from the canvas context menu. In this case, a blank rule is created.

  • Copy from the Reusable components sidebar or duplicate from the rule element context menu. In this case, the rule is copied or duplicated from the source and has the same settings. You can change the settings as needed.

    If you duplicate a rule, all subsequent changes in the source and the duplicate are synchronized. If you copy a rule, the changes in the copy and source are synchronized.

Alternatively, you can create a custom rule by editing the composite rule source code in the Drools language in the Code Editor mode.

Composite rule example
package com.freedomoss.requester;
# list any import classes here.
import java.util.Map;
import java.util.ArrayList;
import com.freedomoss.objective.model.CompositeRuleContext;
import com.freedomoss.objective.model.CompositeRuleDataItemContext;
import org.slf4j.Logger;

# declare any global variables here
global CompositeRuleContext source
global Logger log
global Map params

# RuleContext.SPIT_RULE:usa
rule "Rule context initialization"
auto-focus true
no-loop
agenda-group "initialization-group"
when
$ctx:CompositeRuleContext(initialized == false);
then
# insert processed facts into memory
$ctx.updateWorkingMemory();
# move to business rules
kcontext.getKnowledgeRuntime().getAgenda().getAgendaGroup("calculation").setFocus();
end
# RuleOutcome.Definition={"outcomeId":"Group I","conditional":false,"conditions":[]}
# RuleOutcome.Definition={"outcomeId":"Group II","conditional":false,"conditions":[]}
# RuleOutcome.Definition={"outcomeId":"Group III","conditional":false,"conditions":[]}
# RuleOutcome.Definition={"outcomeId":"Group IV","conditional":false,"conditions":[]}
# RuleOutcome.Definition={"outcomeId":"Group V","conditional":false,"conditions":[]}
# RuleOutcome.Definition={"outcomeId":"outcome1","conditional":false,"conditions":[]}
rule "Send unprocessed result to unconditional outcome(s)"
agenda-group "calculation"
dialect "mvel"
salience 80
when
$ctx:CompositeRuleContext(initialized == true);
$item:CompositeRuleDataItemContext();
then
$ctx.sendResultToUnconditionalOutcomes($item, true);
$ctx.logExecutedRule(kcontext.getRule().getName() + " item:" + $item.toString());
end
rule "Logging all items"
agenda-group "calculation"
dialect "mvel"
salience 60
when
$ctx:CompositeRuleContext(initialized == true);
$item:CompositeRuleDataItemContext(this memberOf $ctx.lastStepDataItems);
then
$ctx.logExecutedRule(kcontext.getRule().getName() + " item:" + $item.toString());
end

Set composite rule

To set a rule, double-click the respective element on the canvas or right-click it and select Edit from the context menu.

On the Rule Editor page, proceed as follows:

  1. Enter a unique name for your rule.

  2. Click Add Outcome if there is none. Each rule must have at least one outcome.

  3. Click Add Condition to create a condition for the outcome.

    You can add multiple conditions to one Outcome. If you leave Outcome without any conditions, this means all other Records.

    The logic of rule elements is as follows:

    • AND between Conditions
    • OR between Outcomes
  4. Set up conditions for your outcomes. Each condition contains three required fields. These are as follows:

    • Answer Code, or the name of the column in the data file. The field is autocompleted.
    • Logical Operator, for instance, equals, less than.
    • Value, or a regular expression (matches regexp, not matches regexp). RegExp allows you to use the OR logic in the condition values by adding the pipe | symbol, for instance, 1|2.
  5. Save the rule by clicking Save.

  6. Connect the newly created outcomes to the target tasks or processes.

Apply additional functions related to composite rules by enabling advanced rule options or advanced outcome options.

Advanced rule options

APPROVE_ALL_RULE

If set, the Drools execution is replaced with a Java loop that unconditionally sends all records to the next step.

SPLIT_DATA

The flag enables splitting records for the next step based on the number of created tasks.

Create a composite rule with the SPLIT_DATA flag after a Bot Task using the multi-column export plugin (with split-results="true") to split a single record into multiple ones.

To minimize data errors when data record splitting is required, avoid adding the SPLIT_DATA rule after the step that splits records in its export section.

SPLIT_RULE and JOIN_RULE

The flags are used in BPs where all records going to the fork have to pass through all branches and join afterward. The step after the JOIN rule won't start until all branches are completed.

A group label—the value inserted after a flag—is used to differentiate between split-join groups in case they are used more than once, for example, if a BP has sub-processes with the split and join operations.

STREAMING

The flag overrides BP streaming settings for the subsequent step. If set, defines the number of tasks or a percentage value for streaming.

NAMED_RULE

The flag is used to build cut-off rules in a BP based on model results. The rule is used after the extract step and allows you to generate a condition automatically.

Advanced outcome options

warning

The Enable logging feature under the advanced outcome options is obsolete.

There is only one advanced outcome option—Enable logging. If you apply it, the rule execution is recorded to rules.log.

RegEXP in conditions

RegEXP allows you to use the OR logic in composite rules for a parameter.

For instance, num matches regexp 1|2 means that the outcome accepts records with the num value of 1 OR 2. Otherwise, the record is redirected to the default outcome.