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
ruletask ruleTaskName { body = dynamicselect(?rule) {action1 ... actionr} };
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
select
or dynamicselect
keywords (comprehension). The code must
return a value of type boolean
. The selection method changes the way the filter is
applied to the rules. With dynamic rule selection, the filter is evaluated each time the rule task
is invoked.
With the decision engine, there is no difference between
dynamicselect
and select
. They behave the same way in that the
statement is called each time the task is executed.
With the classic rule engine, the difference between the
dynamicselect
and select
keywords lies in the number of times that
the code is evaluated.
-
A
dynamicselect
statement is called each time the task is executed. -
A
select
statement is called only once, the first time the task is executed.
(?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.util.Date)?rule.getPropertyValue("effectiveDate"));
}
In
the previous example, ?contract.country in { "France", "Spain", "Italy"}
is
evaluated once per task execution and
?contract.effectiveDate.after((java.util.Date)?rule.getPropertyValue("effectiveDate"))
is calculated once per rule for each task execution. body = dynamicselect(?rule) {
return ?contract.effectiveDate.after((java.util.Date)?rule.getPropertyValue("effectiveDate")) &&
?contract.country in { "France", "Spain", "Italy" };
}