Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Java script help in Live Cycle Designer

Avatar

Level 2

Hi

Can you please let me know how to identify whether value in a decimal field has  decimal

if value has decimal, i need to ignore that value during summation.

Requirement is as follows

A table has 2 columns. Column 1 has a running number that can have values like 1, 1.1, 1.2, 2

Second column is amount. This can have decimals.

I need to total the amount only for main nos 1, 2.  Amount for rows having decimal should be ignored

code i use as part of  calculate

var fields = xfa.resolveNodes("Subform1.Table1.Row1[*]");

xfa.host.messageBox("fields length"+fields.length);

for(i=0 ; i<fields.length; i++) 

{

  c = xfa.resolveNode("Subform1.Table1.Row1[" + i +"].NF1[*]").rawValue;

how to check if c has decimal?

}

Thanks in advance

Ram

2 Replies

Avatar

Level 10

Hi,

Try the following;


var total = 0;


var fields = xfa.resolveNodes("Subform1.Table1.Row1[*]")


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


{


var row = fields.item(i);


if (Math.floor(row.DecimalField1.rawValue) === row.DecimalField1.rawValue)


{


  total += row.DecimalField2.rawValue;


}


}


console.println(total);



Or maybe, if you aren't doing anything else in the loop;


var total = 0;


var fields = xfa.resolveNodes("Subform1.Table1.Row1.[Floor(DecimalField1) == DecimalField1]")


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


{


var row = fields.item(i)


total += row.DecimalField2.rawValue;


}


console.println(total);



Note you don't need to do a resolveNodes within the loop, the item() method will return the row.

Regards

Bruce

Avatar

Level 2

Dear Bruce

Thanks a ton for the quick help

Appreciate it

Best Regards

Ram