<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<STYLE>.hmmessage P {
        PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px
}
BODY.hmmessage {
        FONT-SIZE: 10pt; FONT-FAMILY: Verdana
}
</STYLE>

<META content="MSHTML 6.00.2900.3492" name=GENERATOR></HEAD>
<BODY class=hmmessage>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face=Arial 
color=#0000ff>Why not simply use something like this:-</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face=Arial 
color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face="Courier New" 
color=#0000ff>rule "TaxCalc"<BR>&nbsp;&nbsp;&nbsp; 
when<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $i : Invoice($st : 
salesTax, $gst : gstRate, $sa : salesAmount, $id : importDuty, $gr : 
govtRebate)<BR>&nbsp;&nbsp;&nbsp; then</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face="Courier New" 
color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$i.setTotalTax(round($st + ($gst * $sa / 100) + $id &#8211; $gr, 
2));</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face=Arial><FONT 
face="Courier New"><FONT color=#0000ff><SPAN class=373395905-03072009><SPAN 
class=373395905-03072009>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
update($i);</SPAN></SPAN><BR>end<BR></FONT></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT color=#0000ff><FONT 
face=Arial>What do you gain by checking whether the Total Tax is different from 
the value of the calculation? </FONT></FONT></SPAN><SPAN 
class=373395905-03072009><FONT color=#0000ff><FONT face=Arial>I must be missing 
something from your simplified example?!?</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT color=#0000ff><FONT 
face=Arial></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face=Arial 
color=#0000ff>(I think, big disclaimer!!) you could achieve your requirement 
using eval and a tax value function that uses a cache under the hood, much like 
the following:-</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face=Arial 
color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face="Courier New" 
color=#0000ff>rule "TaxCalc"<BR>&nbsp;&nbsp;&nbsp; 
when<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $i : Invoice($tt : 
totalTax, $st : salesTax, $gst : gstRate, $sa : salesAmount, $id : importDuty, 
$gr : govtRebate)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
eval(Invoice($tt != taxFunction($st, $gst, $sa, Sid, $gr))<BR>&nbsp;&nbsp;&nbsp; 
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$i.setTotalTax(taxFunction($st, $gst, $sa, Sid, $gr);</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT 
face="Courier New"><FONT 
color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
update($i);<BR>end<BR></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT face=Arial 
color=#0000ff>Evals cannot be indexed so you take a performance 
hit.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT 
face="Courier New"><FONT color=#0000ff><FONT 
face=Arial></FONT>&nbsp;</DIV></FONT></FONT></SPAN>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT color=#0000ff><FONT 
face=Arial>With kind regards,</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT color=#0000ff><FONT 
face=Arial></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=373395905-03072009><FONT color=#0000ff><FONT 
face=Arial>Mike</FONT></DIV></FONT></SPAN><FONT color=#0000ff></FONT><FONT 
color=#0000ff></FONT><BR>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma><B>From:</B> rules-users-bounces@lists.jboss.org 
  [mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Shabbir 
  Dhari<BR><B>Sent:</B> 03 July 2009 01:24<BR><B>To:</B> 
  rules-users@lists.jboss.org<BR><B>Subject:</B> [rules-users] Formula value 
  assginment in LHS<BR></FONT><BR></DIV>
  <DIV></DIV>Dear all<BR><BR>We are developing a financial business application 
  that contains hundreds of business rules for validations and calculations. In 
  the calculation rules we change the value of attribute if values past in the 
  request is incorrect e.g.&nbsp; <BR><BR>rule "TaxCalc"<BR>&nbsp;&nbsp;&nbsp; 
  when<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $i : 
  Invoice()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Invoice 
  (totalTax != (round(salesTax + (gstRate * salesAmount / 100) + importDuty &#8211; 
  govtRebate, 2)))<BR>&nbsp;&nbsp;&nbsp; 
  then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  i.setTotalTax(round(salesTax + (gstRate * salesAmount / 100) + importDuty &#8211; 
  govtRebate, 2));<BR>end<BR><BR>The above code works perfectly fine. Only 
  problem is the perform calculation twice. What I was looking if possible I can 
  store calculated tax in a variable and simply assign variable to attribute if 
  rule condiation fails. Some thing like:<BR><BR>rule 
  "TaxCalc"<BR>&nbsp;&nbsp;&nbsp; 
  when<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $i : Invoice() 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Invoice (totalTax != calTax : 
  (round(salesTax + (gstRate * salesAmount / 100)+ importDuty &#8211; govtRebate, 
  2)))<BR>&nbsp;&nbsp;&nbsp; then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  i.setTotalTax(calTax);<BR>&nbsp;&nbsp;&nbsp; end<BR><BR>But this does not work 
  - shows system error at calculated value assignment. Is there any work 
  around?<BR><BR><BR>
  <HR>
  Click here to find out more <A 
  href="http://windowslive.ninemsn.com.au/article.aspx?id=802246" 
  target=_new>POP access for Hotmail is here!</A> </BLOCKQUOTE></BODY></HTML>