Expand my Community achievements bar.

SOLVED

how to access rows in table via script

Avatar

Former Community Member

I have a floating numerical field in a table that's populated by a database. When previewing it uses a sample XML file. The path to the field is:

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

That was obtained by copying the path from the script window. I have a numerical field which I hope to get the total into someday, but for debug purposes, in the calculate event I used the following:

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

This displays 28 which is the correct number of rows on the page. To try and sum all F11a fields I tried the following:

var row = topmostSubform.Page.Content.Repeater.Table1.Row1;
var sum = 0;
for (var j=0;j<row.all.length;j++) sum += row[j].F11a.rawValue;
sum;

I don't get anything with that. Probably there's a script error. Could someone tell me what to do. Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Weird, I replied to this this afternoon from work but my reply doesn't seem to exist!

Search in the help under "Calculating sums of fields", there are Javascript examples of calculating sums from within repeating subforms which is what table rows are.

If you use Formcalc it's quite easy to do with wildcards. In the help search for "to perform calculations in a table" and there's a picture that shows how to use wildcards for calculating in tables. Basically it's along the lines of "sum (Table.Row[*].Field[*])

So in your case the following might work:

sum (topmostSubform.Page.Content.Repeater.Table1.Row1[*].F11a[*])

View solution in original post

3 Replies

Avatar

Former Community Member

I tried the following and it doesn't work:

var rows = topmostSubform.Page.Content.Repeater.Table1.Row1.all;
var sum = 0;
for (var j=0;j<rows.length;j++) sum += rows[j].F11a.rawValue;
sum;

If I returned rows.length it displays 28, which is correct. From what I read it seems "rows" should be a collection of Row1 nodes, and if so there should be a F11a on each one.

Avatar

Former Community Member

If I use the following:

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

The value of the first F11a is passed to the field I hope to contain a total, and it displays that. How do I iterate through all the rows and total F11a? Thanks

Avatar

Correct answer by
Level 10

Weird, I replied to this this afternoon from work but my reply doesn't seem to exist!

Search in the help under "Calculating sums of fields", there are Javascript examples of calculating sums from within repeating subforms which is what table rows are.

If you use Formcalc it's quite easy to do with wildcards. In the help search for "to perform calculations in a table" and there's a picture that shows how to use wildcards for calculating in tables. Basically it's along the lines of "sum (Table.Row[*].Field[*])

So in your case the following might work:

sum (topmostSubform.Page.Content.Repeater.Table1.Row1[*].F11a[*])