These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Summing repeating subforms...?

NStonerook
Registered: Feb 15 2011
Posts: 11
Answered

I am trying to add up the sum of a (potentially) repeating subform in LiveCycle Designer. My javasript is as follows:

form1.P1.Desig.Remain::calculate - (JavaScript, client)

var fields = xfa.resolveNodes("desInfo[*].AAmount");
var total = 0;
for (var i=0; i <= fields.length-1; i++) {
total = total + fields.item(i).rawValue;
}
this.rawValue = total;

***desInfo = name of subform
***AAMount = number I want totalled

My problem is the displaying text box stays at "$0.00" without updating the total…
If anyone could help me with this I would greatly appreciate it

Nick

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Accepted Answer
You can use FormCalc for this purpose.
It's way easier to use.

$ = Sum(desInfo[*].AAmount)

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

NStonerook
Registered: Feb 15 2011
Posts: 11
Thanks Radz
NStonerook
Registered: Feb 15 2011
Posts: 11
Radzmar:

The FormCalc formula works just fine. But since my "DesInfo" subform is hidden until someone chooses something... I get an error message right when I open the pdf file that says:

Error: accessor 'form1.P1.Desig.DesInfo[*].AAmount' is unknown.

I know that at this point that value is unknown. Is there any way I can get LiveCycle to NOT give me this error message?

Thanks
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You need to test if the fields exist or not or if the fields have a value.

With JavaScirpt you can use the 'try{}catch{}[finally{}]' statement to trap an error.

George Kaiser

NStonerook
Registered: Feb 15 2011
Posts: 11
The field will eventually exist if the user wants it to... but right from the get go it does not exist.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
That is why you need to test for the existence of the field and if it does not exist then do not perform the rest of the process or try to use the field. The use of "try catch" allows one to trap the error and then control what action to take including ignoring it and not letting the user see the error from the point of the error.

George Kaiser

NStonerook
Registered: Feb 15 2011
Posts: 11
I'm new to LiveCycle / Javascript... I have no idea what to put in the try or catch scripts...
This is my error message:

Script failed (language is formcalc; context is
xfa[0].form[0].form1[0].P1[0].Desig[0].Remain[0])
script=

Remain = Sum(form1.P1.Desig.DesInfo[*].AAmount)
Error: accessor 'form1.P1.Desig.DesInfo[*].AAmount' is unknown.

I want that error message to not pop up for the user....