5 Replies Latest reply on Oct 5, 2011 8:18 AM by philmodjunk

    Script to create new records using table?

    EamonnWilmott

      Title

      Script to create new records using table?

      Post

      Hi,

      I am trying to write a script to create new records quickly. I have a table which is a list of horses names. I have given them each an ID number too. Then in another table which is their daily work record, I want to create one new record per horse name, with a chosen date.

      I have a very basic understandiong of scripts, I can create the new record and go to the date field, but then I want to pause and enter a date, then resume and go to the horse name field and then select the first horse name from the horse name table, then repeat all the steps with the same date, but select the second horses name, etc,etc. Until reaching the last horse name record.

      I hope this makes sense and someone can help!

      Many thanks,

      Oriana

        • 1. Re: Script to create new records using table?
          rjlevesque

          Care to share your solution so I can SEE what you are trying to do with it?  =)

          I feel sure I can help you but I need to get a look at your solution...

           

          Regards,

          RJ

          (sounds like a job for a loop perhaps)

          • 2. Re: Script to create new records using table?
            EamonnWilmott

            I am happy to share, but have got myself into a problem...have tried a loop script, which is now running, and has a pause/continue option, but no option to stop the script!! How can I stop it? Until then I can't get into the other script to copy it to show you...

             

            Esc doesn't work...

             

            thanks

            • 3. Re: Script to create new records using table?
              philmodjunk

              Define a date field with global storage such as gSpecifiedDate. Then use a looping script that loops through all your "horse" records creating one new record for each and entering the date field you selected/entered in the global date field.

              Am assuming this relationship between your tables:

              Horses::HorseID = WorkSchedule::HorseID

              The script:

              #Start from Layout based on Horses
              Show All Records
              Go To Record/request/page [first]
              Loop
                 Set Variable [$HorseID ; value: Horses::HorseID]
                 Go To Layout [WorkSchedule]
                 new record/Request
                 Set Field [WorkSchedule::HorseID ; $HorseID ]
                 Set Field [WorkSchedule::DateField ; Horses::gSpecifiedDate] //gSpecifiedDate must have global storage specified or this won't work
                 Go To Layout [original layout]
                 Go to Record [Next ; exit after last]
              End Loop

              • 4. Re: Script to create new records using table?
                EamonnWilmott

                OK, got out of that...

                 

                Here is the script I have done (won't let me cut and paste so am typing):

                 

                New Record/Request

                Go to Field [FILEMAKER DATABSE::Date]

                Insert Current Date [Select]

                Go to Field [FILEMAKER DATABSE::Horse Name]

                Insert Text [Select; "*Name of Horse 1"]

                New Record/Request

                Go to Field [FILEMAKER DATABSE::Date]

                Insert Current Date [Select]

                Go to Field [FILEMAKER DATABSE::Horse Name]

                Insert Text [Select; "*Name of Horse 2"]

                Etc, etc. The above repeats 60 times and I have entered manually each horse name at *. Its a very long script!

                 

                This works for me to get a list of records, one per horse for today's date, which is very useful. However what I want to do is use the related table which stores the list of horse names, instead of having them manually in the script, which I clearly then have to change each time a new horse is added...

                Also I'd like to be able to select the date, rather than just have the script use today's date, as sometime the updates are done a few days after the event, and sometimes we need to put things in for the future. Also I'd like to be able to create all the records for a month in advance and then just go in and fill in the details later, which is how the staff here are used to working on Excel, and find very useful.

                I hope this all makes sense, as you can see I am a novice.

                many thanks,

                Oriana

                 

                 

                • 5. Re: Script to create new records using table?
                  philmodjunk

                  Please see my example script in my previous post.

                  To post a script to the forum:

                  1. You can upload a screen shot of your script
                  2. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF.
                  3. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.
                  4. 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 look to your script. (Use the HTML option and paste the text into the HTML editor.)