2 Replies Latest reply on Feb 27, 2014 9:03 AM by tglatt

    Simple Loop Question RE Loop Script Exiting After One Loop

    tglatt

      Title

      Simple Loop Question RE Loop Script Exiting After One Loop

      Post

           I have two tables. 

           One table contains dates and other fields I use to store the results of summary calculations. 

           The second table contains quarterly data for many different customers. 

           I am trying to write a loop script that....

           1. sets a date from the first table in a variable called $Date

           2. performs a find in the second table based on the $Date

           3. sets the results of a count summary field in a new variable called $Count 

           4. updates the count field in the first table with data in the $Count variable for the specified date

           5. repeats the process for the next record

           The problem I am running in to is that the script runs once and then exists.

           Here is what I have...

           Go to Record/Request/Page [First]
           Loop
             Set Variable [$Date; Value:Table1::Date]  
             Perform Find *note criteria is written as Table 2::Date: [=$Date]
             Set Variable [$Count; Value:Table2::a_Count]  *note a_Count is an Average Summary Field
             Replace Field Contents [Table1::Count; $Count]
             Go to Record/Request/Page [Next; Exit after last]
           End Loop

            

           I am sure that the answer is pretty simple, but I am not an expert and am unsure what is causing the problem.

           Any suggestions? 

           Running Filemaker Pro 12

        • 1. Re: Simple Loop Question RE Loop Script Exiting After One Loop
          philmodjunk

               Your need two two layouts for this. You can't do it all on one layout.

               Your find is changing your found set each time and thus Go to Record/Request/page [next ;exit after last] is not going to the record that you expect.

               Go to Record/Request/Page [First]
               Loop
                   Go to Layout ["Table 2" (Table 2)]
                   Perform find
                   Set variable [$count
                   Go to Layout [original layout]
                   Go to record/request/page [next ; exit after last ]
               End Loop

               And this assumes that you have used some method to pull up the correct found set of Table 1 records in your script before the first line of this example executes.
                

          • 2. Re: Simple Loop Question RE Loop Script Exiting After One Loop
            tglatt

                 Your comments helped. It was easier to create a third table that listed the dates I need, then use that table as the starting point for the script. The script now loops through the dates in the new table to obtain the correct count in Table2 above and then store the count in the original Table1 above. 

                  

                 Thanks!