8 Replies Latest reply on Apr 5, 2013 4:00 PM by philmodjunk

    Copy Multiple Records w/new Year

    C.Kobel

      Title

      Copy Multiple Records w/new Year

      Post

           I need to copy all found records. For example, my layout has a set of records each year to track visits. The user can already view only "current records" and they're sorted. I need to duplicate every current record and update the year. How can I do this?

            

        • 1. Re: Copy Multiple Records w/new Year
          philmodjunk

               Use a looping script that loops through your found set and uses the duplicate record script step to duplicate it followed by a set field step to update the year field.

                     #Starts from layout based on table with the records you want to duplicate
                     #Before running this script, pull up the found set of the records you need to duplicate
                      Freeze Window
                      Go To Record/Request/Page [first]
                      Loop
                              Duplicate Record
                              Set Field [ YourTable::Year ; Year ( get ( CurrentDate ) )]--> you can change this calculation to enter next year
                              Omit Record
                              Go To Record/Request/Page [first]
                              Omit Record
                              Exit loop If [ get ( FoundCount ) = 0 ]
                      End Loop

          • 2. Re: Copy Multiple Records w/new Year
            C.Kobel

                 I entered the script as you have it above. It's telling me there are no records found after the script is run. What am I doing wrong?

                  

            • 3. Re: Copy Multiple Records w/new Year
              philmodjunk

                   "no records found" is an error message produced after performing a find. There's no find performed by this script so I think I'm missing some details about what you did to get that message. If you have performed a find and can't find the records this script was supposed to produce, Try using Show All records, then go to the last few records in the found set of all recorsd. These will be the most recently created records. If the script created any records, this is where they'd be and you can check them to see if any fields in them do not have the correct information.

                   If no records were created by the script, then you need to check to see what records were in your found set before performing this script.

              • 4. Re: Copy Multiple Records w/new Year
                C.Kobel

                     I got it. Thanks!

                      

                • 5. Re: Copy Multiple Records w/new Year
                  C.Kobel

                       One more question. Is there a way to trigger the script to occurr once per year on 12/31?

                        

                  • 6. Re: Copy Multiple Records w/new Year
                    philmodjunk

                         Sort of. You actually perform the script much more frequently, but have the script exit without doing anything when it's not time to do this yet.

                         You can schedule scripts in FilMaker Server using the Scheduler.

                         You can use an OS based task scheduler such as Windows Task Manager to open a "robot file". The file is a simple FileMaker file with a setting in Field Options that performs a script each time the file is opened. That script uses perform script to run this script in your main file.

                         You can use the same file options script to run the script each time that you open the file, but if you do, be aware that you may not actually open the file on 12/31 every time so you have to build in some flexibility to run a day or two later if it hasn't yet been run. The script can create a record in a table and log the fact that the script was run in that new record so that a subsequent run of the script can look for that record and determine whether or not to do this.

                    • 7. Re: Copy Multiple Records w/new Year
                      C.Kobel

                           I'm concerned that changing computers (when the current office one is replaced) will mean losing the Windows Scheduler and cause problems.

                           I found 2 plug-ins online that seem to allow scheduling scripts at specific intervals. Are you familiar with any of these and would you recommend using them?

                           2empowerFM Script Scheduler

                           ScriptFire for Filemaker

                      • 8. Re: Copy Multiple Records w/new Year
                        philmodjunk

                             I have no experience with either plug in.