Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Sum of fields nested inside a repeating subform (PER PAGE)

Avatar

Former Community Member
I have a form that sums up the order quantity field. The order quantity field is inside a repeating subform, not in a table. I used the below code to do the grand total. It works.



var fields = xfa.resolveNodes("ProductRow[*].OrderQuantity");

var total = 0;

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

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

}

TotalSubform.TotalQuantity.rawValue = total;



QUESTION:

But I also need to do the order quantity total per page. I tried using the below code but I can't get it to work.



var fields = xfa.layout.pageContent(0 , "field", 0);

var total = 0;

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

if (fields.item(i).name == "ProductRow[*].OrderQuantity") {

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

}

}

TotalSubform.TotalQuantityPage.rawValue = total;



Please help. Thanks in advance.
2 Replies

Avatar

Former Community Member
Did you get this to work? If so, please post the answer.

Avatar

Former Community Member
I got the page subtotal to work by setting a MAX number of repeating subform for each data item in OBJECT/BINDING.



var fields = xfa.resolveNodes("ProductRow[*].OrderQuantity");

var total = 0;

for (var i=0; i <= fields.length-1; i++) { total = total + fields.item(i).rawValue; } TotalSubform.TotalQuantity.rawValue = total;



This would work if you have the same number of rows on every page. Not in my case, my first page only has 6 max. The upper half of my first page contains order information. The succeeding pages have a maximum of 10 rows. I'm still working on my solution.