Expand my Community achievements bar.

SOLVED

cannot access row in table

Avatar

Former Community Member

I have a table with numeric fields and need to sum all the rows for a given ciolumn. The path to the field is:

topmostSubform.Page.Content.Repeater.Table1.Row1.F11a

On the calculate event for the sum field, if I use:

topmostSubform.Page.Content.Repeater.Table1.Row1.all.length;

I get a value of 28 which is how many rows are displayed.

If I use:

topmostSubform.Page.Content.Repeater.Table1.Row1.F11a.all.length;

I get a value of 1.

If I use:

topmostSubform.Page.Content.Repeater.Table1.Row1.F11a.rawValue;

I get the value for the first row.

I need to iterate through all the rows. I've been reading the documentation. None of the examples I've seen are for data-driven tables. I am also new to Adobe stuff. If someone would tell me how to iterate through all the rows displayed on the page I would appreciate it. Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

There's a couple of ways depending on if you use Formcalc or JavaScript.

Formcalc is easy because you can use wildcards - if you search the help on "to perform calculations in a table" there's a picture which helps explain what's going on.

Formcalc:

sum (Table.Row[*].Field[*])

So in your case I think the following should work: sum(topmostSubform.Page.Content.Repeater.Table1.Row[*].F11a[*])

You may not need the full path to the table, depends where you are in the form.

Javascript:

If you search help on "calculating sums of fields" there's examples for summing repeating fields of different types.

To calculate the sum of fields nested within a repeating subform (tables are repeating subforms):

Add a calculate event to the Sum field:


var fields = xfa.resolveNodes("detail[*].NumericField1");    

var total = 0;

for (var i=0; i <= fields.length-1; i++) {

        total = total + fields.item(i).rawValue;

}

this.rawValue = total;

In your case I think the "detail[*].NumericField1" would be "topmostSubform.Page.Content.Repeater.Table1.Row[*].F11a".

Hope that helps!

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

There's a couple of ways depending on if you use Formcalc or JavaScript.

Formcalc is easy because you can use wildcards - if you search the help on "to perform calculations in a table" there's a picture which helps explain what's going on.

Formcalc:

sum (Table.Row[*].Field[*])

So in your case I think the following should work: sum(topmostSubform.Page.Content.Repeater.Table1.Row[*].F11a[*])

You may not need the full path to the table, depends where you are in the form.

Javascript:

If you search help on "calculating sums of fields" there's examples for summing repeating fields of different types.

To calculate the sum of fields nested within a repeating subform (tables are repeating subforms):

Add a calculate event to the Sum field:


var fields = xfa.resolveNodes("detail[*].NumericField1");    

var total = 0;

for (var i=0; i <= fields.length-1; i++) {

        total = total + fields.item(i).rawValue;

}

this.rawValue = total;

In your case I think the "detail[*].NumericField1" would be "topmostSubform.Page.Content.Repeater.Table1.Row[*].F11a".

Hope that helps!

Avatar

Former Community Member

Thanks Jono. What you gave me doesn't work. At least you verified the syntax is correct for me. I put in the following:

var fields = xfa.resolveNodes("topmostSubform.Page.Content.Repeater.Table1.Row[*].F11a");    
var total = 0;
for (var i=0; i <= fields.length-1; i++) {
        total = total + fields.item(i).rawValue;
}
this.rawValue = total;

I also tried this:

var fields = xfa.resolveNodes("topmostSubform.Page.Content.Repeater.Table1.Row[*].F11a");    
this.rawValue = fields.length;

and it gave me zero, so no fields are being found. If I do the following:

var rows = topmostSubform.Page.Content.Repeater.Table1.Row1.all;
rows.length;

I get 28, which is correct. There are 28 rows displayed. If I do the following:

topmostSubform.Page.Content.Repeater.Table1.Row1.F11a.rawValue;

I get 240, which is the value of F11a in the first row. It is not finding all the rows. The calculate event and associated field is on a master page. Other examples I've seen don't use a master page, but that shouldn't matter. It's supposed to work but doesn't.

Avatar

Level 10

Things get accessed differently when master pages are involved, so that could be the problem. I haven't done much with them though so hopefully someone else here can hop in and shed some light.

You could check the script by taking the fields off the master page and putting them on a form page and see if it works, then you'd know if it was the master page that was causing the problem.

Another trick that Niall showed me (because dealing with master pages can be tricky) was to use a hidden field on the form to hold the script and data, name it the same as the field on the master page and set the binding to Global so the field on the master page duplicates the data.

Here's a thread that mentions how to access master pages:

http://forums.adobe.com/thread/498440

Avatar

Former Community Member

After uploading the form I wrapped everything into a subform then moved to the page. No difference with anything. I think the problem has to do with using a floating field inside a table. I think it's a bug. I've learned a lot since creating the form, and am redoing everything again with no tables.