Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Formcalc to JavaScript

Not applicable
Hi,



I have an invoice form which has fields for InvoiceLineTotal and at the end InvoiceTotal. I got the form working so that LineTotals are calculated (quantity*unitprice) and now I want to make the Invoice total calculation automatic.



I managed to do so with formcalc but as follows:



Sum(InvoiceNotification.InvoiceContent.InvoiceLineItem[*].TotalLineAmount)



But all the other scripts in the form are JavaScript so I would prefer to use JavaScript to this calculation too. The problem is that I just can't get this damn thing to work. Has anyone written a general function in JavaScript which would work like FormCalc sum function?



br,

Kari
3 Replies
Not applicable
Kari,<br /><br />Click on the link below to see an example that is done in javascript to calculate the sum.<br /><br />http://66.34.186.88/LiveCycleSamples/.3bbc10bf.pdf<br /><br />The javascript is on the total field on the 'calculate' event.<br /><br />var nTotal = 0; <br />var oAmountFlds = xfa.resolveNodes("xfa.form.form1.page1.Amount[*]"); <br /><br />for( var i=0; i<oAmountFlds.length; i++) <br />{ <br /> if (oAmountFlds.item(i).rawValue != null) <br /> { <br /> nTotal += parseFloat(oAmountFlds.item(i).rawValue); <br /> } <br />} <br />this.rawValue = nTotal;
Dave_Erho
Level 3
Level 3

Hi,

Any chance that you could post this example pdf again?

I need to turn my FormCalc sum for a repeatable table into a javascript sum express because of some additional conditions that I had to include in the calculate field.

Thanks,

Dave

Not applicable
Thank you!



Copied, pasted and modified - Works like a charm!



Actually I had similar loop solution in my mind, but I didn't get the reference to the actual lineAmount formfield to work.



Now I (in fact the whole forum) have a good, clear example on this too.



But thanks again, this was a big help to me



Kari