5 Replies Latest reply on Nov 26, 2013 8:19 AM by philmodjunk

    Help with a Loop in script

    shae1725

      Title

      Help with a Loop in script

      Post

           I'm trying to set a variable from a portal field (Portal A)  and set another portals (Portal B)  fields contents with the variable, run a script, wait 10 secs

           Then return to (Portal A) go to next record and repeat until all Portal A records used!

            

           I use the loop feature a lot but I think this one is more than my basic scripting skills can deal with!

           Any help would be appreciated

            

           go to object "Portal A"

           go to Portal Row "First"

           Set Variable (GetActivePortalRow) $$r

           Set Variable Field::A  $A

           LOOP

               go to object "Portal B"

               go to Portal Row  "First"

               Set  Portal_2_Field::A  $A

               RUN SCRIPT X

               Pause Current Script 10 sec

               go to object "Portal A"

               go to Portal Row $$r + 1

               Set Variable Field::A  $A

               Set Variable (GetActivePortalRow) $$r

           End Loop

             

        • 1. Re: Help with a Loop in script
          philmodjunk

               The script is missing  an exit loop condition.

               As written, the script looks like it will loop through all the portal rows of portal A copying a value from a field in the portal's record to a variable, but each time, it sets the first record in Portal B to the value copied.

               I doubt that this is what you want your script to do.

               Which row in Portal B should get the value from Portal A? Do they always have the same number of records in each portal?

               Many script for doing this type of looping through portal rows are set up to use Go To Related Records in order to pull up a found set of records on a layout based on the portal's table. This avoids having to go to specific portal rows and the script simply flips back and forth between layouts as needed. But this can also trip script triggers with the layout change so you also have to look out for that complication.

          • 2. Re: Help with a Loop in script
            shae1725

                 Hi Phil

                 Yes no exit loop in the example. forgot to add.

                  

                 "As written, the script looks like it will loop through all the portal rows of portal A copying a value from a field in the portal's record to a variable, but each time, it sets the first record in Portal B to the value copied"

                 I wrote the example to keep it simple but the Portal B row is actually set by a  global variable    ie  go to portal row $$Ref   which has already been set on a script that runs before the one I'm building.

                 the script seems to set the GetActivePortalRow $$r to the Portal B list as when the loop runs $$r will only go as high as records in Portal B?

                 which I think is why Im having problems. What do you think?

                  

                  

            • 3. Re: Help with a Loop in script
              philmodjunk

                   I think that I would need to see the actual script.

                   To post a script to the forum:

                     
              1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
              2.      
              3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here. (with this approach, you can get multiple script steps on the same line, please edit the pasted text by inserting some returns to separate those steps.)
              4.      
              5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
              6.      
              7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
              • 4. Re: Help with a Loop in script
                shae1725

                     I think the script that gets triggered inside the main script is messing with the result  (seem to be using the same local variable name in the integral script ) If I cant solve will post for you to have a look.

                     Many Thanks again Phil

                • 5. Re: Help with a Loop in script
                  philmodjunk
                       

                            I think the script that gets triggered inside the main script is messing with the result

                       The best way to spot such interference is to use FileMaker Advanced's script debugger to watch the script execute step by step. If your script trips a script trigger, it's script will pop up in the middle of your current script and executes before control returns to the original script and you can watch it happen in the debugger and see what affect it has on your original script.