0
votes

I have a list of rules with same agenda-group. These rules are interdependent. The rule monthly PI is dependent upon rule annual PI and the value of annual PI is also a fact for drools working memory. It works only when I change the agenda-group name or remove lock-on-active true (but goes into a loop even if i use no-loop). Inside when condition for monthly PI rule I'm checking if annual PI is not null then trigger the rule but it doesnt work as it doesnt fetch the updated value for it. Kindly suggest me what to do ?

rule "Annual P&I one"
@attribute("interestRate,originalLoanAmount")
agenda-group "loaneconomics"
salience 500
lock-on-active true
when 
$loanFact:LoanFact30Yr(loan.loanEcon.interestRate!=null)
then
System.out.println("::::Annual P&I Working ::::: ");

modify($loanFact){
$loanFact.getLoanRuleResult().getLoanEconomics().setAnnualPI( /*FORMULA*/  );
}
end

rule "Monthly P&I one"
@attribute("AnnualPI")
agenda-group "loaneconomics"
salience 400
lock-on-active true
when 
$loanFact:LoanFact30Yr( $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI() != null )
then
System.out.println(":::: Monthly P&I Working ::::: ");
System.out.println("Monthly Payments ::: " + $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI()/12f);
modify($loanFact){
getLoanRuleResult().getLoanEconomics().setToorakMonthlyPI( $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI()/12f );
}
end
1
no-loop only keeps it from looping within a single execution. All bets are off when you start modifying working memory. Have you tried using update?Roddy of the Frozen Peas
I tried using update but no luck. If I keep everything same and change the agenda-group it works fine. Or if I remove lock-on-active true and no-loop then also it works but with loop and even with no-loop its keeps on looping. I don't understand that it doesn't pickup the modified value of the fact while evaluating when condition in a rule with same agenda-group but with different agenda-group or without no-loop or lock-on-active true it picks up the modified fact in the drools working memory.ALS

1 Answers

0
votes

lock-on-active will basically prevent any new activation during the current fireAllRules() invocation. Take a look at this answer to see possible solutions for your problem: what is the difference between no-loop and lock-on-active in drools