Expand my Community achievements bar.

SOLVED

Accessing Nodes to copy names to a List

Avatar

Level 5

I am trying to copy names on the list at the top of this page to a BCC list below it with the action of one button click. However findind the correct node to access with the loop variable "i" is becoming very difficult if not impossible. Any suggestions? Thanks.

https://workspaces.acrobat.com/?d=BfzTUdfSbgoGQjOsZUaj9Q

1 Accepted Solution

Avatar

Correct answer by
Level 5

Correct code for the button is:

//Count rows

var rows = resolveNodes("form1.Page1.Document.OnethruTen.OneThruFour.Four[*]"); //count the rows

var nRows = rows.length-1; //assign row count to variable

// Create new array to hold sorted array data[][][]...

var nameArray = new Array ();

//Loop through the number of #4 subform instances obtaining values for each textfield

for ( i=0; i<= nRows; i++)

{

    //Fill array with values from #4 subform

    nameArray[(i*2)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").Owner.rawValue;

    nameArray[((i*2)+1)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").DF.rawValue;

}

console.println(nameArray);

//Loop through the values of the array and place them in the BCC list

for ( i=1; i<= nRows+1; i++)

{

        if ( i <= nRows )

        {

            this.resolveNode('form1.Page1.ActionOwner.Table1._Name[0]').addInstance(1);

                if (xfa.host.version < 8) {

                                            xfa.form.recalculate(1);

                                          }

        }

    form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField1.rawValue = nameArray[((i*2)-2)];

    form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField2.rawValue = nameArray[((i*2)-1)];

}

View solution in original post

8 Replies

Avatar

Level 10

Hi,

I get a "The document can't be found, or you do not have access to it." message trying to access your file. 

Is it shared?

Bruce

Avatar

Level 5

It wasn't published properly. Should be available now. Thanks Bruce.

Avatar

Level 10

Hi,

Try this;

//Count rows

var rows = resolveNodes("form1.Page1.Document.OnethruTen.OneThruFour.Four[*]"); //count the rows

var nRows = rows.length - 1; //assign row count to variable

console.println(nRows);

// Creat new array to hold sorted array data[][][]...

var nameArray = new Array ();

console.println(nameArray[0]);

//Loop through the number of #4 subform instances obtaining values for each textfield

for ( i=0; i<= nRows; i++)

{

//nameArray[i] = nRows.item(i).rawValue;

nameArray[i] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").Owner.rawValue;

}

//Loop through the values of the array and place them in the BCC list

for ( i=0; i<= nRows; i++)

{

form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField1.rawValue = nameArray[i];

}

I have highlighted the bits I have changed.

Regards

Bruce

Avatar

Level 5

Bruce,

Thank you for getting me back on the correct path. The file linked above works solid now. I have some questions if you have a moment.

1. What does [" + i + "] mean or do?

2. I have added an "addInstance" script that has some strange behavior. Adjusting the number subtracted from "nRows" influences the operability of this script and I haven't found the relationship yet of why "nRows" without any subtraction doesn't work. I get an error:

xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four[" + i + "]") is null

var nRows = rows.length-1; actually works, but leaves off the .Four[2] content from the BCC list.

3. console.println(nameArray); prints the values of the nameArray but the nameArray values are duplicates. Why are there duplicates? My understanding of Arrays is that:


nameArray[0] will equal Douglas, Donald M

nameArray[1] = Winkle, Perry H

nameArray[2] = Panther, Ida B

and so on.........

Update Answer #3: The duplicates occur because the console.println command is inside the loop.



Version 2 of the file is found at:

https://workspaces.acrobat.com/?d=I00OjiRSn7dHapyPgyiH5w


Avatar

Correct answer by
Level 5

Correct code for the button is:

//Count rows

var rows = resolveNodes("form1.Page1.Document.OnethruTen.OneThruFour.Four[*]"); //count the rows

var nRows = rows.length-1; //assign row count to variable

// Create new array to hold sorted array data[][][]...

var nameArray = new Array ();

//Loop through the number of #4 subform instances obtaining values for each textfield

for ( i=0; i<= nRows; i++)

{

    //Fill array with values from #4 subform

    nameArray[(i*2)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").Owner.rawValue;

    nameArray[((i*2)+1)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").DF.rawValue;

}

console.println(nameArray);

//Loop through the values of the array and place them in the BCC list

for ( i=1; i<= nRows+1; i++)

{

        if ( i <= nRows )

        {

            this.resolveNode('form1.Page1.ActionOwner.Table1._Name[0]').addInstance(1);

                if (xfa.host.version < 8) {

                                            xfa.form.recalculate(1);

                                          }

        }

    form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField1.rawValue = nameArray[((i*2)-2)];

    form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField2.rawValue = nameArray[((i*2)-1)];

}

Avatar

Level 10

Hi,

The [" + i "] is just a way of specifing the correct occurance of the field so Four[0], Four[1], Four[2], etc.  There's a bit more of this in John Brinkmans blog, http://blogs.adobe.com/formfeed/2011/06/resolvenode-vs-resolvenodes.html

Your second second question I think is because the SOM expression of a repeating item starts at zero, so if you have 3 occurences they will be index 0, 1 or 2.

Regards

Bruce

Avatar

Level 5

Thanks for the article Bruce.

SCRIPT:

var numOcc = resolveNodes("form1.RCCAP.Document.OnethruFourteen.FiveThruTen.Fourteen.Action[*]");

var numCount = numOcc.length;

console.println("numOcc = " + numOcc);

console.println("numCount = " + numCount);

for this script I get:

CONSOLE:

numOcc = [object XFAObject]

numCount = 3

The number 3 is correct. However the [object XFA Object] answer doesn't make sense to me.

Avatar

Level 10

Hi,

The variable numOcc is an XFAObject, so it will have a className property.  So numOcc.className will tell you what type of XFAObject, if it is a field the numOcc.ui.oneOfChild.className will tell you what type of field.  If it is a text field then it will have a rawValue property giving you the content of that field.

Hope that helps

Bruce