5 Replies Latest reply on May 17, 2010 2:10 AM by BatMan

    Feeding data into FM from Applescript: fastest way

    BatMan

      Title

      Feeding data into FM from Applescript: fastest way

      Post

      Hi. I'm feeding my FM Pro 11 Advanced database with data from an AppleScript. The current way this is done is via the "set cell" command in a layout that contains the target fields. However, this seems to be very slow. Each time a field is fed with a value, the FM layout does a refresh, which is unnecessary and takes a lot of time. I need to fill in hundreds or thousands of fields. Isn't there a faster way to do that? Like, "locking" the layout to prevent the rendering engine from updating the layout every time a cell value has been set, and only releasing it after everything has been filled in. Or like filling in the data in the background, i.e. not in a layout that is being shown and redrawn all the time.

       

      I appreciate your ideas!

        • 1. Re: Feeding data into FM from Applescript: fastest way
          FentonJones

          One thing I've found is that the fastest way to bring data into FileMaker is to write the AppleScript so that it does not cause FileMaker to actually "go" to the record. Because, as you've seen, the screen flashes when you change records. I've never seen it flash between setting fields however, only between records.

           

          If you can somehow target the record via a reference, then FileMaker does not have to change the screen. 

           

          I have some examples here, but they're hard to find. Perhaps if you could post the basics of your script, ie., with just a few set cells. It is more the way that you create or reference the record which can speed it up.

          • 2. Re: Feeding data into FM from Applescript: fastest way
            BatMan

            Thank you for the reply. Here's the main raw part of the AS code:

             

             

            repeat with newEntries in newEntryList
                tell application "FileMaker Pro Advanced"
                    tell document "myDocument"
                        show layout "DataManipulationLayout"
                        tell table "data"
                            set theRecord to create new record
                            go to theRecord
                            tell theRecord
                                set cell ...
                                ...
                                set cell ...                 end tell             end tell         end tell     end tell end repeat

             

            I create a few hundred records and fill them all with data (about 100 fields each). This includes strings, numbers, but also images (set cell "image1" to "imagemac:/..."). After each set cell, the window is refreshed. You're right, it doesn't flash, but it reloads all field contents, which gets terribly slow as soon as the first image has been inserted, and is rather slow already before that, when only strings and numbers have been filled in.

             

            • 3. Re: Feeding data into FM from Applescript: fastest way
              IwaoAVE!

              You can provide field data as list when creating a record as follows.

              create new record with data {"data1", "data2", ...}

              Another thing I noticed is that your script repeats entire task.
              Less repetition would make it faster.

              Assuming 'newEntries' is a list of field data, here's an improved version of your script.

              tell application "FileMaker Pro Advanced"
                tell document "myDocument"
                  show layout "DataManipulationLayout"
                  tell table "data"
                    repeat with newEntries in newEntryList
                      create a new record with data newEntries
                    end repeat
                  end tell
                end tell
              end tell

              Note that the item order of 'newEntryList' must match with the order of the fields on the 'DataManipulationLayout'.

              Hope this helps,
              Iwao


              • 4. Re: Feeding data into FM from Applescript: fastest way
                FentonJones

                Iwao's way is likely the fastest, basically a "list from a list". But here is a basic example of what I was talking about earlier. To set the fields of a new record, without actually going to/showing the new record. With a FileMaker Freeze Window step beforehand. You would still want to be on a layout with all the fields. Though you could avoid this by using a "layout" reference in the cell address. It is a little weird to look at while it's happening, as we're used to seeing FileMaker show the new record. But it is much faster not to.

                 

                setrectocreaterecordatend

                tellrec

                    setcell "Album" toalbum_name

                    setcell "Name" totrack_name

                    setcell "Artist" toartist_name

                endtell

                • 5. Re: Feeding data into FM from Applescript: fastest way
                  BatMan

                  Thank you (both of you) for your valuable answers and hints.