Search code examples
javadroolsrule-enginebusiness-rules

How to fire a rule only if other rule has been fired?


Let's say I've two rules-

rule1 will be fired if conditionA and conditionB are satisfied.

rule2 will be fired if conditionC and condition D are satisfied.

I want to write a rule3 which should be fired if rule1 and rule2 have been fired? Ideally I would like to be able to use operators e.g.-

fire rule3 if rule1 **AND** rule2 have been fired

fire rule3 if either rule1 **OR** rule2 has been fired. 

In other words, how do I refer to a rule's firing in another rule?

I can obviously use conditionsABCD in rule3 but I am sure there must be an elegant way to handle this scenario.

Ideally, I want to keep rule1, rule2 and rule3 in one DRL file.


Solution

  • You can add a fact on rule1 when conditionA and conditionB are ok named rule1ok and the same for rule2 with rule2ok. Then you can check the new conditions rule1ok and rule2ok for rule3.