AnsweredAssumed Answered

Loop repeats exactly once - result is 2x the expected result

Question asked by DavidLamb on Aug 31, 2013
Latest reply on Aug 31, 2013 by DavidLamb

Title

Loop repeats exactly once - result is 2x the expected result

Post

     This is my first Filemaker project.  My script is intended to add up the values in a field on a list of records.  The value is recorded in a field called PurposeAmt in a table called Purpose.  Purpose is in the portal on another layout.  The script runs from the main layout.  Eventually, I'll add a GTRR command to return to the main layout, but I need to resolve this issue. Here is the script

     Begin script...

     Set Variable [$$TransactionTotal; Value:0]
     Go to Related Record [Show only related records; From table: "Purpose"; Using layout: "Purpose" (Purpose)]
     Go to Record/Request/Page [First]

     Loop
       Set Variable [$$TransactionTotal; $$TransactionTotal + PurposeAmt]
       Show Custom Dialog ["TransactionTotal is " & $$TransactionTotal]
       Go to Record/Request/Page [Next; Exit after last]
     End Loop

     ...End script

     The Show Custom Dialog is just for debugging purposes.  

     If I have five related items in the table, I can watch the custom dialog display the first item, then the next time it displays it's the first item + second item, etc.  I expect it to stopp adding when it comes to the fifth and last item.  However, it then goes through the list again, adding each item up.  In the end, the total value of $$TransactionTotal is 2x what it should be.

     How do I make it do this only once?

     Thanks for any help!

Outcomes