5 Replies Latest reply on Jul 16, 2012 2:37 PM by philmodjunk

    Script that Inserts PDF into a container field



      Script that Inserts PDF into a container field


      Hello FM Users!


      I'm having difficulty taking PDFs that are currently orgainized in individual serial number-named folders (was using SuperContainer) and moving them to into the new FM12 container fields as reference only files.

      I've been trying to create a looping script that finds the PDF based on the name of the folder that it's contained in on my desktop (folder name is the records serial number) but then how do I tell FileMaker to grab that PDF file and place it into the container field? I can only get as far as setting up the file path to the folder but not the file. There are thousands of PDFs and doing this manually is not an option for me. I feel like I'm missing something simple.

      Your help is greatly appreciated.

        • 1. Re: Script that Inserts PDF into a container field

          Exactly where do you encounter trouble? Can't get the name of the file or can't get Insert PDF to work?

          • 2. Re: Script that Inserts PDF into a container field

            Thank you for replying Phil.


            I run into problems with "copying" the PDF file name and adding it to the file path as a variable ($FilePath)

            • 3. Re: Script that Inserts PDF into a container field

              "Copying" from where? A field in your database or is it that you need a list of all files in the specified folder so that you can use them to build the needed paths in the variable?

              If you need the list of directory contents, you may need to do one of the following:

              1. Get a plug in. Don't know if it's FMP 12 compatible, but mooplug is free and incldes a function for listing directory contents.
              2. Move the folder in to your documents directory. Theres a get function that will list all the files and folders in your documents folder so you can parse the list returned to extract the names and file paths of all objects enclosed in a directory IF it's inside the documents folder.
              • 4. Re: Script that Inserts PDF into a container field

                I would need it to search a directory on my hard drive. I could definitely move the directory of PDFs to my documents folder and use the get function that you mentioned in your option 2. The function is "Get ( DocumentsPathListing )" which would seem to me as a good start to what I'd like to do. Here's an example of some of the text I received form using Get ( DocumentsPathListing ):


                /Macintosh HD/Users/Me/Documents/DatabaseFiles/Files/Database/FILES/FIL0008/09-EKC002_InkCartridgeLabel.pdf

                /Macintosh HD/Users/Me/Documents/DatabaseFiles/Files/Database/FILES/FIL0009/09-EKC002_introColorCartridgeLabel.pdf

                /Macintosh HD/Users/Me/Documents/DatabaseFiles/Files/Database/FILES/FIL0010/ColorXL_Carton.pdf

                /Macintosh HD/Users/Me/Documents/DatabaseFiles/Files/Database/FILES/FIL0011/BlackXL_Carton.pdf


                 The text in blue are the individual folders that are named after the record's serial number and the text in green are the names of the PDF files that i've been trying to get. How would I then go about filtering that huge list of file paths down to single out the one directory line i'd like to set as a variable?

                Thank you Phil; I think I'm almost there!

                • 5. Re: Script that Inserts PDF into a container field

                  For starters, you don't need to separate out the text in green. You can assign an entire line from this listing to your $FilePath variable to get the path to the file in it's temporary, documents directory based location.

                  The first entry for the goup of items inside this diretory will be the path to the dirctory itself:

                  /Macintosh HD/Users/Me/Documents/DatabaseFiles/Files/Database/FILES/FIL0008/

                  So you can use code such as:

                  Set Variable [$PathsList ; value: Get ( DocumentsPathListing ) ]
                     Set Variable [$K ; value: $K + 1]
                     Exit loop if [GetValue ( $PathList ; $K ) = "/Macintosh HD/Users/Me/Documents/DatabaseFiles/Files/Database/FILES/FIL0008/"]
                     Exit Loop if [ $K > valuecount ( $PathList )]
                  End Loop

                  To loop through the entries until you get to that first one, then you can loop until the leading text changes to that of a new directory.

                  I help another user by creating a demo for this type of "batch Insert" in an .fp7 file you can examine: https://www.dropbox.com/s/1lg85eymwpymsh8/BatchFileInserter.fp7