Summing fields in a subform

Summing fields in a subform

Hello. 

I'm relatively new to Creator and Deluge and I'm hoping someone might be able to help me solve an issue I'm having with a Creator app I'm building.

In this app, I have a mainform and a subform. Each row of the subform has a "Total" field which I have managed to automatically calculate. What I am trying to do, however, is sum up the amounts in every row's "Total" field, and display that in a field on the main form.

My early attempts at scripting this resulted in various form execution errors, until I finally found that *seemed* to work, but although math is being done in the field, the result is almost always wrong (too high). I assume the issue is a scripting error on my part-- bad code, code in the wrong place, or both, but I can't seem to figure out where the problem is.

For reference, I've included a screen grab of my form. I am trying to get the Total Hours Worked field on the mainform to correctly add up the values in all the Total fields on the subform.   The code I'm using to try to accomplish this as shown below, and I'm putting it in "On User input" for every field in the subform.

If anyone can point me in the right direction, I'd really appreciate it.

Thanks.

Joe

  1. for each  total in Daily_Hours_Worked
  2. {
  3. if(row.Total != null)
  4. {
  5. grandTotal = grandTotal + row.Total;
  6. }
  7. }
  8. input.Total_Job_Hours_for_Week = grandTotal;