3 Replies Latest reply on Mar 14, 2012 4:26 PM by iamsloper

    Scripted Import, add fields to Data File in Separation Model

    BenGraham

      Hi All,

       

      I am having trouble figuring out how to write an import script. Here is the scenario: I have a distributed Separation Model with Interface, Data and Media files. I realized that I need to correct a formula in a subsummary field and add a few more fields to the Data file, my extra fields are all used up.

       

      I saw this post by PhilMonkJunk in the FileMaker Forum:

       

      "First you put a script in your original data file and all subsequent releases that goes from layout to layout doing a show all records so that every table occurrence has a found set of all records. This makes sure that all records can be imported from the data file.

      The script in your new data file performs this "prepare for import" script as it's first task.

      Then your script is just a series of Import Records steps set up to import the records from the old into the new.

      To update serial number fields, you can sort your newly imported records and then use go to record [first] or go to record [last] (depends on your sort order) to go to the record with the largest serial number value. You can then use the Set Next Serial Value step to set the value to at least one number larger than this maximum.

      If you want to be even more user friendly, you can define a container field and use insert file with the store by reference option to insert a reference to the original file in this container field. This allows you to pop up an open file dialog where your user finds and opens the original file. Your script then extracts the file path to the original file from the container and stores it in a variable so that your Import Records steps can all refer to this variable for the file path to the original file.

      After the import is complete, either the user or a utility script can copy and rename files to replace the old data file with the new."

       

      1. My Data file that is distributed does not have a "prepare for import", although I have now added it to the new file that will replace the distributed file for future imports. The interface already has file references to the original file and can run the "prepare for import" script with the utility layouts within the interface file.
      2. Then my challenge is to then close the old data file, referenced and originally opened by the interface, and open the New Empty Data file ready for import with the same file name that will end up being the clients new data file.
      3. I am having trouble attempting to use the script steps to do this part of PhilMonkJunk's post: "If you want to be even more user friendly, you can define a container field and use insert file with the store by reference option to insert a reference to the original file in this container field. This allows you to pop up an open file dialog where your user finds and opens the original file. Your script then extracts the file path to the original file from the container and stores it in a variable so that your Import Records steps can all refer to this variable for the file path to the original file." It seems to be in the wrong sequential order. I am not sure how to get the file path of the original data file after the user opens it using Open File dialog.

       

      If anyone can shed any light on this I would be grateful.

       

      Thanks so much,

      Ben