I think this overly complex (unless other things have to be considered as well.<br><br>As I interpret these three rules, it is required to compute the sum<br>of all values ABC.C with equal ABC.A<br><br>declare DistinctAT<br>
d_auditT : String<br> d_sum: Double<br>
end<br>
<br>rule "create DistinctAT on first ABC"<br>when<br> ABC( $a:A )<br> not DistinctAT( d_auditT == $a )<br>then<br> DistinctAT $disAT = new DistinctAT();<br>
$disAT.setD_auditT($AT);<br> insert( $disAT );<br>end<br><br>rule "update d_sum in DistinctAT"<br>when<br> $disAT: DistinctAT( $a: d_auditT )<br> ABC( A == $a, $c:C )<br>then<br> $disAT.setD_sum( $disAT.getD_sum() + $c*0.13 );<br>
end<br><br>Notice that I do not update/modify $disAT in the second rule since this would cause a loop.<br>If you need the update to fire other rules, add "no-loop true".<br><br>To get all results, you can use a query; run it after all ABCs have been inserted.<br>
<br>-W<br><br><br><div class="gmail_quote">On 17 September 2010 08:35, Ritesh <span dir="ltr"><<a href="mailto:ritesh.khot@sungard.com">ritesh.khot@sungard.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi,<br>
<br>
I have 3 rules in my drl file and want the last one should get fired only<br>
after all the facts in rule1 and rule2 gets inserted in working memory.<br>
Please see below code for more understanding. Please suggest.<br>
<br>
Thanks<br>
<br>
declare DistinctAT<br>
d_auditT : String<br>
end<br>
<br>
declare ActualSum<br>
auditT : String<br>
sumOfThree : BigDecimal<br>
end<br>
<br>
rule "insert combined sum"<br>
dialect 'java'<br>
when<br>
ABC( $a:A, $b:B, $c:C )<br>
<br>
then<br>
BigDecimal actSum = $c.multiply(0.13);<br>
ActualSum $as = new ActualSum();<br>
$as.setAuditT($a);<br>
$as.setSumOfThree(actSum);<br>
insert($as);<br>
System.out.println("AT :" + $movAuditT);<br>
end<br>
<br>
rule "insert distinct AT"<br>
<br>
dialect 'java'<br>
when<br>
$a : ActualSum( $AT : auditT )<br>
not DistinctAT( d_auditT == $AT )<br>
then<br>
DistinctAT $disAT = new DistinctAT();<br>
$disAT.setD_auditT($AT);<br>
insert($disAT);<br>
System.out.println("Done!");<br>
end<br>
<br>
rule "Get Sum Group by AT"<br>
<br>
dialect 'java'<br>
when<br>
<br>
DistinctAT( $dAT: d_auditT )<br>
<br>
$total : Double()<br>
from accumulate( ActualSum( auditT == $dAT, $actSum_Main : sumOfThree ),<br>
sum( $actSum_Main ) )<br>
<br>
eval(<br>
chkRuleExpre( $total,$lfna_SEI,$r_SEI )<br>
)<br>
<br>
then<br>
System.out.println("Done Main Rule, total :" + $total);<br>
end<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deactivate-a-rule-tp1516088p1516088.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deactivate-a-rule-tp1516088p1516088.html</a><br>
Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>