I have two rules:
// rule values at B31, header at B7
rule "Regular Cms Recalc Hierarchy Table_31"
salience 65516
when
$rcri: RegularCmsRecalcInfo(myIsHandled(false), myGetCommissionModelId(9318), myGetProductTypeId(3073), eval(RuleDateParser.isAfterOrEqual($rcri.myGetPolicyStartDate("1.1.1800"), "1.1.1800")), eval(RuleDateParser.isBeforeOrEqual($rcri.myGetPolicyStartDate("31.12.2999"), "31.12.2999")), eval(RuleDateParser.isAfterOrEqual($rcri.myGetContractDate("1.1.1800"), "1.1.1800")), eval(RuleDateParser.isBeforeOrEqual($rcri.myGetContractDate("31.12.2999"), "31.12.2999")))
then
$rcri.mySetCmsFullWithdrawalCutoffPastMonths(6);
$rcri.mySetCmsNoWithdrawalCutoffPastMonths(30);
$rcri.mySetLevelingType("PAID_MONTHS");
$rcri.setHandled(true);update($rcri);
end
// rule values at B37, header at B7
rule "Regular Cms Recalc Hierarchy Table_37"
salience 65510
when
$rcri: RegularCmsRecalcInfo(myIsHandled(false), myGetCommissionModelId(9318), eval(RuleDateParser.isAfterOrEqual($rcri.myGetPolicyStartDate("1.1.1800"), "1.1.1800")), eval(RuleDateParser.isBeforeOrEqual($rcri.myGetPolicyStartDate("31.12.2999"), "31.12.2999")), eval(RuleDateParser.isAfterOrEqual($rcri.myGetContractDate("1.1.1800"), "1.1.1800")), eval(RuleDateParser.isBeforeOrEqual($rcri.myGetContractDate("31.12.2999"), "31.12.2999")))
then
$rcri.mySetCmsFullWithdrawalCutoffPastMonths(6);
$rcri.mySetCmsNoWithdrawalCutoffPastMonths(24);
$rcri.mySetLevelingType("PAID_MONTHS");
$rcri.setHandled(true);update($rcri);
end
The first rule has the priority over the second one and the condition is basically the same. The first rule has one more check that the second one: myGetProductTypeId(3073)
. The first rule does not execute code in the “then” statement but the second one does. That would make sense if the object sent trough would fail on myGetProductTypeId(3073)
, but that condition also passes for that object. So I’m just confused why it does not execute the first one. Am I missing something?
To get more insight into this issue I created this “my” methods. So all the methods called in the rules that have “my” in the name are methods that I wrote to debug/log the issue. With that I figured out what I described above.
First I thought that I had a problem with myIsHandled()
method because it used to be at the end of the condition and all previous conditions passed, but now that I moved it to the front nothing changes. It passes normally and so do all other conditions after in the rule.
Edit: After an even more in depth review I noticed that the “then” statement of the first rule actually gets executed but not before other rules are checked.
So first the rule B31 is checked and every condition is true, the “then” statement does not execute even though it should. Then all the rules from B32 to B36 are checked and they fail on condition which is right behavior. Then rule B37 is checked and every condition is true, and B31 “then” statement is executed.
This is even more confusing to me. Why check other rules before executing the one that was already right? If the statement would execute at the right time, the second rule would already fail on myIsHandled(false)
.
1