Search code examples
droolsbusiness-rulesdrools-flow

how to use only updated value in drools


I am having a drl file with 2 rules

The 1st rule updates a attribute, say updates attribute b to 10 based on some condition.

The 2nd rule has a check for values with b not equal to 10. It logs error for those values not equals to 10.

The b value gets updated to 10 in rule 1. However in the second rule it does not use updated value and logs error.

Is there a way to use the updated b value in the 2nd rule. I tried using modify but still the error gets logged.


Solution

  • The "modify"-keyword is the right thing. Can you please post the exact error? Maybe this is just a syntax problem. The modify keyword is used to inform the engine about the change in the working memory e.g.:

    rule "First Rule"
    dialect "mvel"
    when 
      // conditions for the first rule
      $obj : MyObject()
    then  
      // modify attribute of the object
      modify($obj){number = 10 };
    end