You'd need to make sure you inform the engine that Order's price has changed:-<br><br>when<br> ...<br>then<br> modify( $o ) {<br> setPrice( $o.getPrice() - 20);<br> }<br><br>You could also consider using agenda-groups or lock-on-active to provide your behaviour.<br>
<br><b>agenda-groups<br></b><br> rule "rule 1"<br>//implied default agenda-group of MAIN<br>when<br> $o : Order (amount>100 && <200);<br>then<br> modify( $o ) {<br> setPrice( $o.getPrice() - 10);<br>
}<br> drools.setFocus("next step in calculation");<br>end<br><br>rule "rule 2"<br>//implied default agenda-group of MAIN<br>
when<br> $o:Order (amount>200);<br>
then<br> modify( $o ) {<br> setPrice($o.getPrice() - 20);<br> }<br> drools.setFocus("next step in calculation");<br>
end<br><br>rule "rule 3"<br>agenda-group "next step in calculation"<br>when<br> $o : Order(....)<br>then<br> ....<br>end<br><br><b>lock-on-active</b><br><br> rule "rule 1"<br>
//implied default agenda-group of MAIN<br>lock-on-active true<br>
when<br>
$o : Order (amount>100 && <200);<br>
then<br>
modify( $o ) {<br>
setPrice( $o.getPrice() - 10);<br>
}<br>
end<br>
<br>
rule "rule 2"<br>
//implied default agenda-group of MAIN<br>
lock-on-active true<br>
when<br>
$o:Order (amount>200);<br>
then<br>
modify( $o ) {<br>
setPrice($o.getPrice() - 20);<br>
}<br>
end<br>
<br>
rule "rule 3"<br>
agenda-group "next step in calculation"<br>
when<br>
$o : Order(....)<br>
then<br>
....<br>
end<br>
<br><div class="gmail_quote">On 18 March 2011 16:08, Gabor Szokoli <span dir="ltr"><<a href="mailto:szocske@gmail.com">szocske@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi,<br>
<br>
>From what I know, it's generally better to make the rules idempotent:<br>
In your case introduce a discountedPrice field, leaving the original<br>
price alone.<br>
<br>
If you insist on making it run only once instead, you can introduce a<br>
field or fact class to mark an order "discounted", then all<br>
discounting rules know to ignore it. (This gets really complicated if<br>
the order amount ever changes and you do need to run the discounting<br>
rules again.)<br>
<br>
<br>
Gabor<br>
<br>
2011/3/18 yong zhao <<a href="mailto:cluncao@yahoo.com.cn">cluncao@yahoo.com.cn</a>>:<br>
<div><div></div><div class="h5">> Hi<br>
> I just try to uses jboss rules in our projects. I met a question. for<br>
> example<br>
> package sample<br>
> rule "rule 1"<br>
> when<br>
> $o:Order (amount>100 and amount<200);<br>
> then<br>
> $o.setPrice($o.getPrice()-10);<br>
> end<br>
> rule "rule 2"<br>
> when<br>
> $o:Order (amount>200);<br>
> then<br>
> $o.setPrice($o.getPrice()-20);<br>
> end<br>
> if the fact , order's amount is 210. then the rule2 will be executed, then<br>
> the rule1 will be fired . I want to stop the session once some rule is<br>
> executed or how to control the rule flow.<br>
> thanks in advance<br>
> -Yong<br>
><br>
><br>
><br>
><br>
</div></div>> _______________________________________________<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>
><br>
><br>
<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>
</blockquote></div><br>