Drools Decision table rules not using updated values

2.5k views Asked by At

I am using Drools Rules Server as a service. We are using a decision table

Pre Rules Movie Object:  
actor: "unknown"  
movie: "Ghostbusters"  
rating: 9

I have 2 simple rules in a Drools Decision table. The 1st rule checks for a value (movie=="Ghostbusters") and then sets the calls that objects setActor("Bill Murray").

The 2nd rule checks to see what the Actor is. I have 2 rows in this second rule. if Actor == "Bill Murray" it calls an action of setRating(10). And if actor == "unknown" setRating(8)

The first rule fires as expected, and I can printLn the getActor to show it's "Bill Murray" but in the second rule, the actor == "unknown" action always fires. Even if in that row I print getActor it prints "Bill Murray" but it's using the "unknown" rule.

When the object comes back from the rules, it has Actor = Bill Murray and all values set in the rule "correct" but the rules seem to always use the original object I created outside the rule when evaluating rules.

Is there something I have to add to the decision table or the call to invoke the drools rule server to "update" the object between rule tables?

2

There are 2 answers

0
andbi On

you should use update or modify method as described in Drools docs (4.8.4.1, 4.8.4.2):

rule "modify stilton"
when
    $stilton : Cheese(type == "stilton")
then
    modify( $stilton ){
        setPrice( 20 ),
        setAge( "overripe" )
    }
end

this will tell the engine that object has been changed and rules will be reapplied.

0
Ioannis Mitrolios On

I know too much time has passed since you asked the question but for others with the same problem: As stated you should modify the object and not set it. To do this in decision tables add an action column in your RuleTable and in second line you should add:

modify($className){ setActor("Bill Murray")};

Keep the first row under action blank.