Expand my Community achievements bar.

Sum and display messagebox

Avatar

Former Community Member

Okay, so I need to sum the values of a particular cell in a table, display that value, then display a message if they sum to more than 100.  I tried to use javascript, but I couldn't figure out how to make a sum function.  With FormCalc the sum function is built-in and works perfectly, but I can't get the message box to work.  Here's what I have so far (in the calculate event):

Sum(Body[*].Percentage_of_Interest)
if ((Sum(Body[*].Percentage_of_Interest)) > 100) then
xfa.host.messageBox("The percentages you entered sum to more than 100%.  Please check to ensure you have not made an error.", "Error", 0, 0);
endif

If I comment out the bottom three lines, the top one works fine, but if I uncomment them, the field displays 0.00000% and doesn't respond when I change the values of the cells it is adding.  Anyone have any suggestions

1 Reply

Avatar

Former Community Member

I figured it out.  Here's the code I'm using

var sum = 0;
for (var i = 0; i < _Body.count; i++) {
sum += Body.all.item(i).Field_Name.rawValue;
}
this.rawValue = sum;
if (sum > 100) {
xfa.host.messageBox("The percentages you have entered sum to more than 100%.  Pleace check to ensure you have not made an error.", "Error", 0, 0);
}