Calculate table total based on condition - xfa.resolveNode does not work. | Community
Skip to main content
November 28, 2023
Solved

Calculate table total based on condition - xfa.resolveNode does not work.

  • November 28, 2023
  • 3 replies
  • 1623 views

Hello experts,

 

I am new to Adobe forms and i have been struggling to calculate the total of a column based on condition.

My problem is that when i try the code below i cannot access any property of oFields(e.g. length, item...). I tried different combinations but nothing seems to work:

var oFields = xfa.resolveNodes("tblHandlingUnits.rowHUDataTBL[*]");
 
for (var i = 0; i < len; i++){
if (oFields.) // check each row for specific value{
var total = total + oFields.// the amount of the current row{
}

Here is how the Hierarchy looks like:

Can you please give any suggestion?

 

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by koolForms

Assumptions:

1. You want to look at the value of a specific field in each of the repeating table rows to determine if it has a value. If it does, then add that value to the total variable.

2. That rowHUDataTBL is a repeating row in the table.

 

I would use the following:

var total = 0;

var rowCount = frmHUTable.tblHandlingUnits.rowHUDataTBL.instanceManager.count;

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

{

var rowNode = frmHUTable.tblHandlingUnits.resolveNode("rowHUDataTBL[" + i + "]").Name of the field you want to check for value.rawValue;  Example: colGrossVolume.rawValue;

if (rowNode != null)

{

total = total + rowNode;

}

}

 

You may need to input the full path to the repeating table row starting from the top: xfa.form.root node name. ... all the way down to the rowHUDataTBL.

Also use app.alert() or console.println() to debug and show the variable values. You will have to look up the syntax and how to get the Javascript debugger to be active in Designer for the console.println().

3 replies

Vijay_Katoch
Community Advisor
Community Advisor
November 29, 2023

You can write like below:

var total =0;

var oFields = xfa.resolveNodes("tblHandlingUnits.rowHUDataTBL[*]");
for (var i = 0; i < oFields.length; i++){
var rowInstance = oFields.item(i);
 
// Now with rowInstance you can access  any fields inside this
total += parseInt(rowInstance.(path to your field).rawValue);
}

 

 

 

November 29, 2023

Hi Vijay,

 

Thank you for you reply.

The issue is that after i define var oFields i cannot use any of the property of this object after i type oFields.

I tried with lenght, item but it does not work.

 

Any suggestions?

November 29, 2023

Just to add that the following syntax is working:

var len = xfa.resolveNodes("tblHandlingUnits.rowHUDataTBL[*]").length;

but doesnt work if i try it like:

var len = xfa.resolveNodes("tblHandlingUnits.rowHUDataTBL[*]");

var temp = len.length;

koolFormsAccepted solution
Level 3
November 29, 2023

Assumptions:

1. You want to look at the value of a specific field in each of the repeating table rows to determine if it has a value. If it does, then add that value to the total variable.

2. That rowHUDataTBL is a repeating row in the table.

 

I would use the following:

var total = 0;

var rowCount = frmHUTable.tblHandlingUnits.rowHUDataTBL.instanceManager.count;

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

{

var rowNode = frmHUTable.tblHandlingUnits.resolveNode("rowHUDataTBL[" + i + "]").Name of the field you want to check for value.rawValue;  Example: colGrossVolume.rawValue;

if (rowNode != null)

{

total = total + rowNode;

}

}

 

You may need to input the full path to the repeating table row starting from the top: xfa.form.root node name. ... all the way down to the rowHUDataTBL.

Also use app.alert() or console.println() to debug and show the variable values. You will have to look up the syntax and how to get the Javascript debugger to be active in Designer for the console.println().

kautuk_sahni
Community Manager
Community Manager
December 4, 2023

@tsvetelinge Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni