Expand my Community achievements bar.

SOLVED

Dynamic Table Sum Not Calculating on Commit

Avatar

Level 2

I am using the below code to sum a dynamic table.  Each time I add a second "Table1.Row1" row, and select the value that would render countU ==0 true, the Livecycle form will not re-calcuate the query correctly unless I re-select the first row "Table1.Row1" countU value.  In other words, the dynamic table has two levels of expansion.  When I try to add more row under each primary row, the calculation does not automatically run.  Any suggestions?  Thanks in advance!

var sumD = 0;

var countS = this.resolveNodes("TableA.Row1[*].Subform2[*].Table1.Row1[*].MBRS");

var countT = this.resolveNodes("TableA.Row1[*].Subform2[*].Table1.Row1[*].NON");

var countU = this.resolveNodes("TableA.Row1[*].Subform2[*].Table1.Row1[*].CLC");

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

{

if(countU.item(i).rawValue==0)

{

sumD += (countS.item(i).rawValue * countT.item(i).rawValue);

}

}

sumD

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I'm not sure I understand your structure you seem to have an inner repeating subform then a repeating table, that would be three levels.  Either way you will need to reference the instanceManager count property so the calculation script knows to run when the value changes, so something like;

var sumD = 0; 

var tableARows = this.resolveNodes("TableA.Row1[*]")

for (var i = 0; i < TableA._Row1.count; i++) {

    var tableARow = tableARows.item(i);

    var table1Rows = tableARow.resolveNodes("Subform2.Table1.Row1[*]");

    for (var j = 0; j < tableARow.resolveNode("Subform2.Table1")._Row1.count; j++) {

    table1Row = table1Rows.item(j);

        if (table1Row.CLC.rawValue == 0) {

            sumD += table1Row.MBRS.rawValue * table1Row.NON.rawValue;

        }

    }

}

sumD;

Regards

Bruce

View solution in original post

3 Replies

Avatar

Level 3

Please try to shar your form if possible, in order we can help you with you issue.

thanks.

Avatar

Correct answer by
Level 10

Hi,

I'm not sure I understand your structure you seem to have an inner repeating subform then a repeating table, that would be three levels.  Either way you will need to reference the instanceManager count property so the calculation script knows to run when the value changes, so something like;

var sumD = 0; 

var tableARows = this.resolveNodes("TableA.Row1[*]")

for (var i = 0; i < TableA._Row1.count; i++) {

    var tableARow = tableARows.item(i);

    var table1Rows = tableARow.resolveNodes("Subform2.Table1.Row1[*]");

    for (var j = 0; j < tableARow.resolveNode("Subform2.Table1")._Row1.count; j++) {

    table1Row = table1Rows.item(j);

        if (table1Row.CLC.rawValue == 0) {

            sumD += table1Row.MBRS.rawValue * table1Row.NON.rawValue;

        }

    }

}

sumD;

Regards

Bruce

Avatar

Level 2

Thanks Bruce,

It was the instance manager - I used the exeCalculate( ) in another part of the form, and tested it with an app.alert to ensure the rows were then counting the number of instances correctly to perform the calculation properly.