dynamicselect

The dynamicselect keyword specifies the dynamic selection of a rule.

Purpose

This keyword is used to specify the dynamic selection of a rule in a rule task body.

Context

Rule task definitions

Syntax

    body = dynamicselect(?rule) {...}

Description

The body of a rule task contains a list of rules. You can either specify each rule name explicitly (extension) or have the list of rules computed from the code, which uses the dynamicselect keywords (comprehension). The code must return a value of type boolean. It is evaluated each time the rule task is invoked.

To optimize performance, the decision engine does not execute the code statements the same number of times depending on whether they are before the use of the (?rule) variable or after. Statements that come before the statement in which the (?rule) variable is used are calculated only once per ruletask execution, when the task body is evaluated. Statements including and after the first statement in which the (?rule) variable is used are calculated for every rule under review in the task scope. For example, ?contract is a ruleset variable with a country attribute and an effectiveDate attribute, and the task applies only for a selection of countries and only to the rules whose effectiveDate covers the one of the contract:
body = dynamicselect(?rule) { 
return ?contract.country in { "France", "Spain", "Italy"} &&
       ?contract.effectiveDate.after((java.time.*)?rule.getPropertyValue("effectiveDate"));
}
In the previous example, ?contract.country in { "France", "Spain", "Italy"} is evaluated once per task execution and ?contract.effectiveDate.after((java.time.*)?rule.getPropertyValue("effectiveDate")) is calculated once per rule for each task execution.
However, if you write the following code, then both conditions are calculated once per rule for each task execution:
body = dynamicselect(?rule) {
return  ?contract.effectiveDate.after((java.time.*)?rule.getPropertyValue("effectiveDate")) &&
        ?contract.country  in { "France", "Spain",  "Italy" };
}