4 Replies Latest reply on Jan 27, 2017 6:23 PM by arby

    Script for reinserting files in container field

    arby

      I have a few hundred photos in container fields that I inserted with the option Store only a reference to the file turned ON. The storage option for the container field is Store container data externally.

       

      I need to reinsert those photos with the option Store only a reference to the file turned OFF. The reason is that I’m preparing the database for a WebDirect implementation, and WebDirect does not support container files as references. The storage option—external--will remain the same. Obviously, I’d like to do this via a script rather than manually.

       

      The document in_depth_container_fields_fm14_en.pdf (page 15) contained exactly what I thought I needed:

      "Files inserted by reference can be reinserted as external data using the following 2-step FileMaker script:"
      Set Variable [ $path; GetAsText (referencedContainer) ]
      Insert File [ Insert; referencedContainerField ; $path ]

       

      This script contains two errors: 1) step 1 should say GetAsText (referencedContainerfield) so it matches the field reference in step 2 and 2) $path in step 2 should be enclosed in quotation marks (yes, even though it's a variable. When you enter the variable in the Specify file dialog box, FileMaker encloses the variable in quotes in the Insert File script step).

       

      I ran this script (with the necessary changes to the field name to match my database), but it didn’t work.There was no change to the GetAsText(containerField) result

       

      The test of success, I believe, is this: When an image is inserted with the option Store only a reference to the file turned ON, the result of GetAsText(containerField) look like this:

       

      size:1200,1794

      image:Graphics/graphic.jpg

      imagewin:/C:/Users/MyDocuments/Databases/My Database/Graphics/graphic.jpg

       

      When a file has been inserted with the Store only a reference to the file turned OFF, the result of GetAsText(containerField) should look like this:

       

      remote:graphic.jpg

      size:1200,1794

      DPI:200

      JPEG:PHOTO/FullImage/graphic.jpg

       

       

        • 1. Re: Script for reinserting files in container field
          TSGal

          arby:

           

          Thank you for your post.

           

          The quickest solution would be to pull down the File menu and select "Save a Copy As..."

           

          Near the bottom, click the pop-up to the right of "Save a:" and select "self-contained copy (single file)"

           

          This will create a new file and all remote containers and referenced containers will now be embedded.

           

          If you want to continue with the script, then use MiddleValues function to get the imagewin line.  For example,

           

          Set Variable [ $path ; MiddleValues ( GetAsText(<containerField>) ; 3 ; 1 ) ]

          Go To Field [ Select/perform ; <containerField> ]

          Insert Picture [ "$path" ]

           

          For testing purposes, you may want to create a new Container field (NewContainerField) and modify the script:

           

          Set Variable [ $path ; MiddleValues ( GetAsText(<containerField>) ; 3 ; 1 ) ]

          Go To Field [ Select/perform ; <NewContainerField> ]

          Insert Picture [ "$path" ]

           

          If some of the files are already embedded, then create a calculation in the script to check to see if $path begins with "imagewin".  If so, then update.  If not, go to the next record.

           

          Let me know if you need additional clarification.

           

          TSGal

          FileMaker, Inc.

          • 2. Re: Script for reinserting files in container field
            arby

            Thank you for your response. The "quick" solution isn't a solution for me. I need to retain the option to store container data externally. Saving the file as a self-contained copy embeds all of the images, making the file very large -- and very slow.

             

            My understanding is that a picture can be inserted in a container field with the option Store only a reference to the file selected or not selected. Each one works with the external storage option turned ON. This is confusing, I know.

             

            I need to reinsert all of the image files with store only a reference turned OFF but external storage turned ON.

             

            I'll try the script modification you recommended, which I very much appreciate.

            • 3. Re: Script for reinserting files in container field
              JEDtech

              After you have the new file with the embedded images you can then re-host and set the container storage to external and it will move them all out.

              • 4. Re: Script for reinserting files in container field
                arby

                Hmmm...I didn't know you could do that. Easy solution.

                 

                I also came up with a way to accomplish the same thing using a script, which follows the basic idea set forth in the in_depth_container_fields_fm14_en.pdf  document.

                 

                Assuming that there is a field in the table that stores the filename, e.g., TABLE::filename which has been derived via GetAsText from existing metadata and that path to the image file is stored externally in C:/Folder/AnotherFolder:

                 

                 

                Set Variable [$path; Value: "imagemac:/C:/Folder/AnotherFolder/"&TABLE::filename]

                #Use imagewin instead of imagemac for Windows

                Go to Field [TABLE::containerField]

                Insert Picture [$"path"]

                #Notice that the Reference option is not specified in the Insert Picture step

                 

                These steps insert the graphic file in the container, but this time with the Store only a reference option turned off.

                 

                I put these steps inside a loop and updated 450 container fields without a problem. Now the image files are still stored as external data but with the option Stored only a reference turned off.