2 Replies Latest reply on Sep 12, 2010 8:48 PM by JCPython

    Creating Multiple Records By Script?



      Creating Multiple Records By Script?


      Hey guys,

      Im having trouble with a script, basically i have the following 5 fields (all text box) and 1 button to trigger script:

      Storage Type:
      Rack/Stack #:
      Container Info:
      Starting Number:
      How Many To Create:

      Create Records (button)

      So now when i click the create records button i want filemaker to create as many records as "How Many To Create:" indicates but like i said im not sure how to do this, im sure it has something to do with a loop, but im really unsure on how to script it, been trying all night.

      any ideas?

        • 1. Re: Creating Multiple Records By Script?

          Hi JCPython,

          Use global fields to hold your selections, something like gStorageType, gRackStack# etc.  Fill in your preference in each of the fields you have listed above then click your 'Create Records' button.  Back up first and then pseudo script would then be something like:

          #  first remove all existing records from the found set (this isn't required but it makes process easier)
          Freeze Window
          Go To Record/Request [ First ]
          Omit Multiple Records [ without dialog ; Get ( FoundCount ) ]
          # now you have no records so begin creating your new ones
          # create your first record
          New Record/Request
          Set Field [ StorageType ; gStorageType ]
          Set Field [ RackStack# ; gRackStack# ]
          ... repeat with all your fields
          Exit Loop If [ Get ( FoundCount ) = gHowMany ]
          Duplicate Record
          End Loop

          You could also use Replace Field Contents[] after you create your records but I prefer to do it in the moment.  If you wait until you are done, you risk possibility that someone else finds one of these new records and locks it.

          UPDATE: I changed the script to use Duplicate since the data will be the same in each field.  It should be faster than setting each record with the field values ; instead we just duplicate the first new record after we have filled in the values we want.

          • 2. Re: Creating Multiple Records By Script?

            Thanks so much LaRetta! that works great, i think i was way off lol