Expand my Community achievements bar.

SOLVED

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

Avatar

Level 1

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:

TsvetelinGe_0-1701188874919.png

Can you please give any suggestion?

 

Thank you!

1 Accepted Solution

Avatar

Correct answer by
Level 3

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().

View solution in original post

6 Replies

Avatar

Community Advisor

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);
}

 

 

 

Avatar

Level 1

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?

Avatar

Level 1

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;

Avatar

Community Advisor

what is not working here, seems valid code. try to print to check if it shows the length value.

 

app.alert(temp);

Avatar

Correct answer by
Level 3

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().

Avatar

Administrator

@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