Question

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.

Was it helpful?

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.

OTHER TIPS

One of four best practices I always teach is that rules should not invoke or reference other rules.

When you have rules referencing other rules, your rules get bogged down in implementation details and cease to be solely focused on your policy.

One of the other best practices is that rules should not duplicate the conditions of other rules.

So... @zenbeni's answer above is good advice. You could consider what it means in your policy model when rule1 is true and derive a new fact in the model based upon that. Same for rule2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top