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

Counting Subform Instances

stonesrock
Registered: Feb 27 2007
Posts: 54
Answered

Not sure what I'm missing here, but real close, I'm hoping someone can help me over this "bump"

I have a repeatable subform in a Dynamic PDF form I'm building in LS 8.0, this function is working fine. What I want is to pass a value to a text box for each instance (1, 2, 3, etc.). I have this script that passes the value and is counting, but the value for each instance passes on to all the fields (so if I'm on 3rd instance, the text box shows 3 on all subforms added.

The script is as follows on the text box calcualte event (using Java):

var tableIndex = xfa.form.root.P1.subfrm_AllSubs.subFrm_ActionFollowUp.instanceManager.count
this.rawValue = tableIndex

Thanks in advance if someone can help me clear this up.

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
To count form objects like repeating fields or subforms, you will need a for expression to loop through the whole form.

This sample from the LCD reference manual explains how to count all textfields in the form.
// Count the number of text fields in a document.// Get the field containers from each page.for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {var oFields = xfa.layout.pageContent(nPageCount, "field");var nNodesLength = oFields.length;var nCount = 0;for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit") {nCount++;}}TextField1.rawValue = nCount;}

To access a specific field placed in a repeating subform you need the [] accessor.
As the index of form objects is 0-based you have use [0] to access the first instance of the object, [1] for the second, [2] for the third and so on...
xfa.resolveNode("Subform[1].TextField").rawValue = "this is the third instance";

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

stonesrock
Registered: Feb 27 2007
Posts: 54
Thanks radzmar, that did the trick.