0
votes

I have a simple rule case here

salience 50
no-loop true
rule "1"
    when
        input: Input(a == 20, b == 16026)
    then
        modify(input) {setZ(3)}
end

salience 40
no-loop true
rule "2"
    when
        input: Input(a == 20, c == 209)
    then
        modify(input) {setZ(9)}
end

If I leave the above rules as is, they go into a continuous loop. However, if I modify both rules from:

modify(input) {setZ(9)}

to:

input.setZ(9);

Then the rules execute in order as expected.

My question is: Do I need to use the modify keyword? What does the modify keyword do?

1

1 Answers

1
votes

modify (or update) must be used if the Drools Engine is to re-evaluate rules according to the new value for the modified fact object. Omitting this will not trigger rules where constraints match the new value.

For these two rules, modify is not necessary. But if there is a rule

rule x
when
  Input( z == 9 || == 3 )
then ... end

you would have to use it. In this case, add constraints to your rules:

Input( ..., z != 3 )

and

Input( ..., z != 9 )

respectively, and it will work and you won't even need no-loop any more.