[rules-users] firing rules twice in single session on single object

Davide Sottara dsotty at gmail.com
Fri Oct 12 11:20:03 EDT 2012


A rule like

when
  sales : Sales (salesAmount >=200)
then 
  sales.setSalesMessage("goodsales");
end

will not trigger any new evaluation because the engine can't detect the
change. You'll need to make the engine aware of the change : 

when
  sales : Sales (salesAmount >=200)
then 
  modify (sales) { setSalesMessage("goodsales"); }
end

Notice that "modify" does NOT simply cause rules to re-fire. It causes a
reevaluation of the object which has been modified. Any rule with a pattern
that matches the new version of the object will become active gain. In your
case, since you do not have any constraints on the salesMessage, any
precondition that was holding before the set will be still holding and your
rule will LOOP. You will have to add a "salesMessage == null" condition in
the LHS, or mark the Sales class as @propertyReactive.

I would also like to understand your requirement of "firing rules TWICE"..
do you need to evaluate your fact both before and after setting the message?
(the salesamount would be unchanged)

Davide





--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-firing-rules-twice-in-single-session-on-single-object-tp4020220p4020249.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list