easy-rules icon indicating copy to clipboard operation
easy-rules copied to clipboard

Can we set default action if all the rules failed?

Open shabir1 opened this issue 3 years ago • 1 comments

Can we set default action if all the rules fail? suppose I wrote 50 rules (50 conditions and 50 actions) and if all 50 conditions failed/false now I want to do some default action. like in try-catch block there is finally at the end, or in if .. else if there is else at the end. Similarly, do we have any default action if none of the rules are satisfied?

shabir1 avatar Nov 02 '21 08:11 shabir1

You could try the following

  1. Add an input "fact" to track if any rule was executed. Lets call it haveRulesExecuted
  2. Set up a RuleListener which checks this haveRulesExecuted flag in afterEvaluate and then set it to true if any rule was successfully evaluated.
  3. Set up a rule that has the highest priority and condition which checks the haveRulesExecuted == false. The highest priority will ensure that this is the last rule executed (provided you have no other rule with same priority) and thus if no other rules are executed this "Default" rule will definitely execute.

vshanbha avatar Jun 24 '22 18:06 vshanbha