5 Replies Latest reply on Dec 20, 2016 12:00 PM by reidbloomfield

    How to insert multiple files in container field by using a script with validation

    RajIyer

      Title

      How to insert multiple files in container field by using a script with validation

      Post

      Dear Friends,


      I have a long list of records and each record has its own file, which i am inserting manually in container field and having a hard time with this tedious task.  All file names are sharing the same name as in the Title field. Example:
      Title (text field) - "The Palace" File (container field) - "The Palace.kmz." with an exception of extension (.kmz) at the end.

      All the files that i am inserting are in the same folder.  I need a script that should match the file name with Title in the table and insert the corresponding file from the folder into container field accordingly.

      I am new to Filemaker and don't know about scripting too.  Please advise how to do this? 

      Thank you in advance.


        • 1. Re: How to insert multiple files in container field by using a script with validation
          Rajkumar

          Hi,

          You can write a script (here i m unable to show the screenshot, so follow these guidelines), where you need to set "import record", and specify data source as "folder", and for specify import order, follow these steps:

          1. for import action, choose "update matching records in the found set";

          2. for the target field, set "=" sign, for matching "Title", and set "->" for the container field where u want to insert file;

          3. and check for different "Arrange by" option;and import.

          Check for this, hope it'll work.

          • 2. Re: How to insert multiple files in container field by using a script with validation
            philmodjunk

            The Import Records | Folder action only works with picture, movie and text files. If these files are not of one of these types, you'll need to use a different method.

            If you only need references to the files rather than storing a binary copy of the file in the container, you can construct a calculation field that returns a field type of container that uses the field name in your file to compute a file path to your file.

            • 3. Re: How to insert multiple files in container field by using a script with validation
              FentonJones

              Addendum to Phil's answer. If you need to "embed" the files into the container field, ie., make them independent of the original files, then the same calculation as above could be used in an Insert script step, to get the file. 

              It could be either a relative path (from the FileMaker file), or an absolute path (from the drive's root).

              This would involve setting a script Variable to the calculation, then using that $variable as the path, for an Insert File command. To do multiple files, you'd just Loop within your record set.

              Needless to say, more complex and difficult. It would be best if we knew more. Such as: which OS? Mac? Windows?. What do you intend to do with the files in the container fields later? Is the folder of files always going to be there? Would this need to work in a networked environment? There are several factors which effect how you store and use files in container fields.

              • 4. Re: How to insert multiple files in container field by using a script with validation
                Mingrl88

                     Hi All, 

                     I am trying to do something similar and could use a little guidance if possible, thank you! 

                     So I have 115 records which I imput data into already not realizing I wanted to link each record to a pdf since the record is of a research product published in an article. The good news is of these 115 records the samples only belong to 2 articles. The bad news there is only one file I'd like to import into many records - so it's not like images where each image name matches a certain field and then you just match the fields and voila. It's not that simple - or it seems to be not that simple. 

                     I am thinking if I can do a find and then in a loop script have each record in that found set import this file I think that would work but I'm not sure how to do this for pdfs - or if it's even possible. 

                     Thank you in advance for your time and help with this! 

                • 5. Re: How to insert multiple files in container field by using a script with validation
                  reidbloomfield

                  I know this is an older post, but we were just trying to do a similar thing in our solution (minus the matching up with existing record, but you could modify this to check for that as well). We wanted the user to be able to insert multiple files from a folder into a Documents table wile creating a new record each time. We were able to accomplish this without a plug-in by using the following script:

                  -------------------------------------------------------------------------------------------------------------------------------------

                  Set Error Capture [ On ]

                  #Loop just to make sure the user chooses a folder from their Documents Directory

                  Loop

                  Get Directory [ $DIRECTORY; Dialog Title: "Select the folder to be imported"; Default Location: Get(DocumentsPath) ]

                  If [ Get(LastError) = 1 ]

                  Exit Script [ ]

                  End If

                  Exit Loop If [ PatternCount ( $DIRECTORY; Get(DocumentsPath) ) ]

                  Show Custom Dialog [ Title: "Error"; Message: "Please choose a path that is within your documents folder."; Default Button: “OK”, Commit:

                  “Yes” ]

                  End Loop

                   

                  New Window [ Style: Document; Name: "DMS-IMPORT"; Close: Yes; Minimize: Yes; Maximize: Yes; Zoom Control Area: Yes; Resize: Yes ]

                  Go to Layout [ “@FILEVERSIONS” (docs_FILEVERSIONS) ]

                  Set Window Title [ Current Window; New Title: "DMS-IMPORT" ]

                  Adjust Window

                  [ Hide ]

                   

                  # Get list of all files in the folder directory. This uses a custom function from Brad Dunning called "FilterList". We actually used somewhat of a nested function by first setting "List" as all files under that specific folder and then evaluating the "List" var again to show only the ones with a "." in them. If you don't do this, it will show you folder paths as well, which you don't want to import since they're not files.

                   

                  Set Variable [ $DirList; Value:Let(

                  List = FilterList ( Get(DocumentsPathListing) ;"Contains" ; $DIRECTORY ; 0) ;

                  FilterList ( List ;"Contains" ; "." ; 0)

                  ) ]

                   

                  # Get a total number of files to be imported so you can exit the loop when completed

                  Set Variable [ $totalcount; Value:ValueCount ( $DirList ) ]

                   

                  Loop

                  Exit Loop If [ $count = $totalcount ] //Exit if completed

                  Set Variable [ $count; Value:$count + 1 ]

                  Set Variable [ $file; Value:GetValue ( $DirList; $count) ]

                  New Record/Request

                  Insert File [ docs_FILEVERSIONS::File; “$file” ]

                  End Loop

                   

                  -------------------------------------------------------------------------------------------------------------------------------------

                   

                  As you can see, this requires that the user have the files within their Documents directory since that is the only place where filemaker can list all the files in the folders and subfolders. With the help of Brian Dunning's custom function, we then filtered it out to show only the ones from the folder the user chose at the beginning.

                   

                  Hope that makes sense! Enjoy!