Expand my Community achievements bar.

SOLVED

instantmanager count not work in javascript

Avatar

Level 4

i have a table in dynamic form with two row and a button to add inatance in second row

second row initial count set to zero

i copy both row data in a  text-field

i set initial count for second row 0

var fields = xfa.resolveNodes("Table6.Row2[*].Cell1");

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

{total = total + fields.item(i).formattedValueValue;}

this.rawValue = Table6.Row2.instanceManager.count ==0 ? "(i) Item 1" + xfa.resolveNode("Table6.Row1.Cell").formattedValue : "(i) itme1 " + xfa.resolveNode("Table6.Row1.Cell1").formattedValue + "\n(ii) item2 " + total;

but it not worked and always show second row data

plz help to correct script

1 Accepted Solution

Avatar

Correct answer by
Level 10

So far ist not clear, what kind of field your're using. And your script has some flaws or typos  – see the comments.

var fields = xfa.resolveNodes("Table6.Row2[*].Cell1");

var total = 0;

// a property "formattedValueValue" does not exist

// What type of field is Cell1 – text or numeric?

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

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

}

// Is it "Table6.Row1.Cell" or "Table6.Row1.Cell1"?

// What type of field is it – text or numeric?

this.rawValue = Table6.Row2.instanceManager.count == 0 ? "(i) Item 1" + xfa.resolveNode("Table6.Row1.Cell").formattedValue

: "(i) itme1 " + xfa.resolveNode("Table6.Row1.Cell1").formattedValue + "\n(ii) item2 " + total;

However, I guess this should do the trick.

var oRow2Cells = xfa.resolveNodes("Table6.Row2[*].Cell1"),

oRow1Cell = xfa.resolveNode("Table6.Row1.Cell1"),

nTotal = 0,

i;

for (i = 0; i < oRow2Cells.length; i += 1) {

nTotal += parseFloat(oRow2Cells.formattedValue);

}

this.rawValue = "(i) Item 1" + parseFloat(oRow1Cell.formattedValue) + (oRow2Cells.length > 0 ? ("\n(ii) item2 " + nTotal) : "");

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

So far ist not clear, what kind of field your're using. And your script has some flaws or typos  – see the comments.

var fields = xfa.resolveNodes("Table6.Row2[*].Cell1");

var total = 0;

// a property "formattedValueValue" does not exist

// What type of field is Cell1 – text or numeric?

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

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

}

// Is it "Table6.Row1.Cell" or "Table6.Row1.Cell1"?

// What type of field is it – text or numeric?

this.rawValue = Table6.Row2.instanceManager.count == 0 ? "(i) Item 1" + xfa.resolveNode("Table6.Row1.Cell").formattedValue

: "(i) itme1 " + xfa.resolveNode("Table6.Row1.Cell1").formattedValue + "\n(ii) item2 " + total;

However, I guess this should do the trick.

var oRow2Cells = xfa.resolveNodes("Table6.Row2[*].Cell1"),

oRow1Cell = xfa.resolveNode("Table6.Row1.Cell1"),

nTotal = 0,

i;

for (i = 0; i < oRow2Cells.length; i += 1) {

nTotal += parseFloat(oRow2Cells.formattedValue);

}

this.rawValue = "(i) Item 1" + parseFloat(oRow1Cell.formattedValue) + (oRow2Cells.length > 0 ? ("\n(ii) item2 " + nTotal) : "");