9 Replies Latest reply on Sep 17, 2013 9:47 AM by philmodjunk

    Help with Repeating Script to read from Multiple records

    shae1725

      Title

      Help with Repeating Script to read from Multiple records

      Post

           I have a script to run using content from 3 or 4 fields in a record depending on how many records there are i want the script to repeat through all the records!

           Will be only 6-7 records max

           The help I need is how to assign a variable to the fields or should I just use the Table::Field in the script

           How do I repeat the script and how I make it go to the next record if one is present

           I hope I have explained myself ok

        • 1. Re: Help with Repeating Script to read from Multiple records
          philmodjunk

               It's a bit vague. Almost all scripts that use Loop use one of two ways to control when the loop should be exited:

               Exit Loop If [     ]. If the expression in the brackets is true (just like the If step), the loop is exited at that point.

               Go to Record/Request/Page [next ; Exit after last]

               This step moves you to the next record in your found set unless you are already on the last record. If you are on the last record this step causes you to exit the loop.

               (Once upon a time, the ONLY branching script available in a Filemaker script was Go to Record with the exit after last step. I can recall using it in place of an IF step, which did not yet exist, if you can imagine...)

          • 2. Re: Help with Repeating Script to read from Multiple records
            shae1725

                 I think I understand.

                 Exit Loop If [ ]      what do i put in this function?

                 Also how do you set a field as a variable: I am assuming you use the LET function

                  

                 Many thanks

                  

                  

            • 3. Re: Help with Repeating Script to read from Multiple records
              philmodjunk

                   Since you are looping through records, apparently, you may not need exit loop IF step at all.

                   I need an understanding of what exactly you need the loop to do and under what conditions it should stop looping.

              • 4. Re: Help with Repeating Script to read from Multiple records
                shae1725

                     The  loop will re-run the the script through all the records ie 4 records will have 4  loops

                     Conditions to stop looping  -  exit on the last record!

                      

                     Should I just set the Records::fields variables from within the script

                      

                • 5. Re: Help with Repeating Script to read from Multiple records
                  philmodjunk

                       And what besides looping through the records will it do? (Maybe a loop is not even needed.)

                       The basic structure for looping through records in your found set looks like this:

                       #Perform a find, use go to related records or something to produce a found set of the records you want to loop through first
                       Go to Record/Request/Page [First]
                       Loop
                         #Do stuff here with the current record
                         Go to Record/Request/Page [Next ; Exit after Last ]
                       End Loop

                       But please note that I have assumed a number details that may not be true for your situation. It might be that the records you want to loop through aren't the only records in your found set, for example.

                  • 6. Re: Help with Repeating Script to read from Multiple records
                    shae1725

                         sorry if im not being clear as Im only learning the proper fm terminology!

                         what the repeating script is doing is drawing a graphic (using 3rd party plugin functions) in a container based on the data in my table

                         each record in the table refers to parameters used by the plugin functions. some times there will only be one record and usually max 6 records

                         Each record uses exactly the same fields and script

                          

                          

                    • 7. Re: Help with Repeating Script to read from Multiple records
                      philmodjunk

                           And what script step do you use with those third party plug in functions?

                           Whatever they are, they would be placed inside the loop right where I have: "#Do stuff here with the current record".

                      • 8. Re: Help with Repeating Script to read from Multiple records
                        shae1725

                             I have run into a little problem!

                             I cant use last record in the loop, is it possible to set (go to record) by calculation instead?

                              

                             ie     go to record (last) -1

                        • 9. Re: Help with Repeating Script to read from Multiple records
                          philmodjunk

                               Please explain that in more detail. Why can't you use the last record? Can you omit it from your found set?

                               Another option is to do this inside your loop:

                               Loop
                                  #Do stuff with current record here
                                  Go to Record/Request/Page [ Next ]
                                  Exit Loop If [ Get ( RecordNumber ) = Get ( FoundCount ) //true only when you are on last record ]
                               End IF