3 Replies Latest reply on May 26, 2014 12:37 PM by DavidR

    Repeating Script help....

    DavidR

      Title

      Repeating Script help....

      Post

           Hey,

           So in my database i have 2 address fields that can be fill in and a vacant for the return mail.. and i have a 3 script that copy the data from the selected address to the used for mailing address. the scripts look something like below for address 1 and 2 with slight variations while the vacant script clears all the fields. initially when a record is created it needs to run the use address 1 script on every record to fill in the mailing address.

           insert text (select, "address 1 to use", yes)
           clear (select, "address 2 to use")
           clear (select, "Vacant")
           copy (select, "adress 1")
           paste (select, "mailing address")
           go to field ("address 1")

           how would i modify the script below to go to next record and repeat the script until the end of the found set of records?

           Loop
           insert text (select, "address 1 to use", yes)
           clear (select, "address 2 to use")
           clear (select, "Vacant")
           copy (select, "adress 1")
           paste (select, "mailing address")
           go to field ("address 1")
           go to record (next)
           end loop

           this seems to work kinda... but the cycle never breaks unless i hit esc....

           THANK YOU!

            

        • 1. Re: Repeating Script help....
          FentonJones

               What your missing in your Loop is the option of your Go to Record [Next]. Select that script step. On the left, near the button, is an [x] Exit after last option; it should be checked. Then the step will read: Go to Record [Next, Exit after last]. 

                
               P.S. You might consider adding a Go to Record [First] step before the Loop starts. Just in case you'd forgot to go to the first record before you started the script. 
                
               Another thing. I almost always use the Set Field step instead of ones like Clear, Copy, Paste. 
               Set Field [ a field; original field ] copies "original field" to "a field"
               Set Field [ original field; "" ] clears "original field"
               ( By default it does what "select" does, all data in the field.)
               ( I think I got it right :-)
               [ Do not test such changes on the real live file; as a mistake could clear data, if in a Loop. FileMaker Pro Advanced, with Script Debugger on is the safest way to see such.]
          • 2. Re: Repeating Script help....
            philmodjunk

                 Fenton has given excellent advice.

                 To expand on it:

                 Copy, paste, clear and script steps that start with "insert" require that the field they reference be present and browse mode accessible on the current layout when they execute. If not, they silently fail to work. I thus avoid using them except when absolutely necessary. Set Field and Set Variable can be used in place of them in most situations and these steps will work even if the field is not on the layout at all.

                 In addition, Copy copies data to the system clipboard. This can irritate and confuse your users when data that they have copied is mysteriously replaced by data copied by your script. Use Set variable to copy the value to a variable and you won't need to use Copy in most cases.

                 Paste can then be replaced by a set field step that looks like this: Set Field [YourTable::field ; $VariableHere ] and you put the variable created by the set variable that you used in place of copy in place of $VariableHere.

                 Clear can be replaced by: Set Field [YourTable::Field ; "" ]

                 Insert Text  can be replaced by Set Field

                 Insert .... steps, because they interact with your layout, also will trip script triggers such as OnObjectEnter or OnObjectExit where set field does not.

            • 3. Re: Repeating Script help....
              DavidR

                   Fenton & Phil,

                   Thank you for your replies, I am not sure how I missed the exit on last check box (I looked like 20 times) and great idea for the go to first record I totally overlooked that.

                   In regards to the copy paste clear information, I had no idea they could be so troublesome if given the right conditions. For now I will leave the copy, paste and clear intact as they are working as expected in the live system. As I don’t have access to the advanced version to debug scripts it will have to wait to be corrected in the database until the next major update I do since I have to work inside of a copy and that a majority of the scripts rely on copy paste and clear at the present time.

                   The joys of working on someone else’s project from 10+ years ago when it was upgraded from a dos system….I'm, not sure whom has the best answer as they are both useful and correct.

                   Thanks again for all the time you guys commit to help novice people such as myself!