Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Data repeats in multiple instances, please help.

Avatar

Level 1

Hi,

I have been working for days on this form using Adobe Livecycle 9 ES2 and need some help.  I am new to LiveCycle and JavaScript, but as you'll see, I've learned a lot .

I have a repeatable subform (GoalSheet) that totals values based on a dropdown:

var len = form1.GoalSheet.Table6._Others.count;

var sum = 0.0;

this.rawValue=0;

if (form1.GoalSheet.Table6.First.Funding1.rawValue==1)

{

sum += form1.GoalSheet.Table6.First.Cost.rawValue;

}

for (var i = 0; i < len; i++){

if (form1.GoalSheet.Table6.resolveNode("Others[" + i + "]").fsource.rawValue==1) {

sum += form1.GoalSheet.Table6.resolveNode("Others[" + i + "]").Cost2.rawValue;

}

}

this.rawValue = sum;

This works beautifully.  However, when the user creates a second instance of GoalSheet, it doesn't work. 

Any suggestions?

A link to the form is here:  https://www.dropbox.com/s/94t48cw2ywcxpcq/4-20%20Draft_total_formcalc_pagination_safetynet%20v126.pd...

Thanks for any and all help!

Michael

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

as the GoalSheet is a repeatable instance as the Others row you have to loop through all its instanced too.

var goalSheets = _GoalSheet.count,

          sum = 0;

for (var i = 0; i < goalSheets; i += 1) {

          var vGoalSheet = form1.resolveNode("GoalSheet[" + i + "]"),

                    vOthers = vGoalSheet.Table6._Others.count;

          if (vGoalSheet.Table6.First.Funding1.rawValue == "1") {

                    sum += vGoalSheet.Table6.First.Funding1.rawValue;

                    for (var j = 0; j < vOthers; j += 1) {

                              sum += vGoalSheet.Table6.resolveNode("Others[" + j + "]").Cost2.rawValue;

                    }

          }

}

this.rawValue = sum;

Hope this helps.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

as the GoalSheet is a repeatable instance as the Others row you have to loop through all its instanced too.

var goalSheets = _GoalSheet.count,

          sum = 0;

for (var i = 0; i < goalSheets; i += 1) {

          var vGoalSheet = form1.resolveNode("GoalSheet[" + i + "]"),

                    vOthers = vGoalSheet.Table6._Others.count;

          if (vGoalSheet.Table6.First.Funding1.rawValue == "1") {

                    sum += vGoalSheet.Table6.First.Funding1.rawValue;

                    for (var j = 0; j < vOthers; j += 1) {

                              sum += vGoalSheet.Table6.resolveNode("Others[" + j + "]").Cost2.rawValue;

                    }

          }

}

this.rawValue = sum;

Hope this helps.

Avatar

Level 1

Thank you so much for your reply.  You are putting me on the right track.

However, in my original code I have two if statements, one to sum the First row and one to sum the Others row.  Would you mind incorporating that in your explanation?  I am having trouble picturing how that looks.

I appreciate your time.

Michael

form1.GoalSheet.PracticeTitle1::calculate - (JavaScript, client)

var len = form1.GoalSheet.Table6._Others.count;

var sum = 0.0;

if (form1.GoalSheet.Table6.First.Funding1.rawValue==1)

          {

          sum += form1.GoalSheet.Table6.First.Cost.rawValue;

          }

for (var i = 0; i < len; i++){

if (form1.GoalSheet.Table6.resolveNode("Others[" + i + "]").fsource.rawValue==1) {

                              sum += form1.GoalSheet.Table6.resolveNode("Others[" + i + "]").Cost2.rawValue;

                    }

          }

this.rawValue = sum;

Avatar

Level 1

I got it working correctly. 

Thank you so much for your help!

Michael