Search code examples
javadrools

How to get a list of all drools variables defined in condition / left hand side from inside the consequence / right hand side?


We need to know which variables were defined in the condition part of a rule and perform some actions with them. Is there any way to retrieve them?

example (note, that I just made this dummy code up, so no garantuee for correctness):

rule DummyRule
when
  $player: Player()
  $team: Team(teamId == $player.teamId)
then
  $player.setDummy(true);
  [for all vars in when-part, e.g. $player, $team]
     someGlobal.processVar($var)
  [endFor]
end

What I need is the part in [] - How can I determine the variables retrieved in when-part? I couldn't find anything in the documentation, so maybe someone can help here.

Regards, Kay


Solution

  • There's a magical variable in the RHS called kcontext of type RuleContext. Maybe from there you can get them somehow.