4 Replies Latest reply on Jun 11, 2014 7:02 PM by krod

    Open a file from container field (open storage)



      Open a file from container field (open storage)


           I have a container field that uses open storage, with the file location specified by the contents of the record fields ("Document Tracker/"&Document Tracker::Document Type&"/"&Document Tracker::Doc Name&"/Version "&Version Number). Is there a script I can write that will open this file. I know I can export the file and open that to view, but I'd rather avoid that if possible.

           I've tried open URL, but I can't seem to make a relative URL open. If I specify the URL for the script, I can get the file to open, but I've got hundreds of files, and more files will continually be uploaded all in slightly different locations with slightly different file names. 

           Am I

           1. Making sense? and

           2. Asking to do something even possible?


        • 1. Re: Open a file from container field (open storage)

               You'll need to use Export Field Contents. I know you'd rather not do that, but it's really your only option. What issues does that cause for your solution? (I may be able to suggest ways to mitigate them.)

          • 2. Re: Open a file from container field (open storage)

                 Thank you PhilModJunk for your reply. My issues with exporting the container file are twofold:

                 1. Duplicate files. I want to avoid having duplicate files on the server, so I figured I could have the export files save to a temp folder that can be cleared out when the database is closed. I set up an AppleScript to delete all files in the temp folder that runs before the database closes, but the problem I run into is that if the user still has the file open, it will not be deleted from temp. Two possible solutions that I don't know exactly how to execute:

                 a. Force the files to close without involving the user. (preferred)

                 b. Create a custom dialog indicating that the files must be closed before the database can be closed with a pause until the user confirms that they have indeed closed all open exported files. 


                 2. Filenames. I have a script tied to a button for the user to export and view the file. I am using the Export Field Contents script, specifying the appropriate target field. I run into an issue with specifying the output file, specifically with the filename. I'd like the user to be able to view as many files as they'd like, but it seems that I would need to specify each filename separately? Is there a way to tell FMP that I want the filename to be "filename +1" to create an infinite series? 


                 Thank you for sharing your expertise. Your help is much appreciated.

            • 3. Re: Open a file from container field (open storage)

                   1) If you are exporting to the user's temporary folder, you should not need an AppleScript to delete these files as they will be deleted automatically when the database is closed. As far as I know, if the user keeps the file open, closes the database and then later closes the file, this file still should not be retained in the temporary folder long term, but this is not a scenario that I have tested.

                   Option b should be possible if you use a system script or a file plug in to check for files in the temporary folder after clearing it.

                   2) There are several approaches for handling this issue. Export Field Contents can use a $Path variable to designate both the location and the file name of the file produced by Export Field Contents. This $Path can include a file name extracted via calculation from the container field and/or it can assign a calculated unique value such as the digits produced from Get ( CurrentTimeStamp ) or a global counting variable that you increment each time.

                   For more on container fields, the $Path variable and the script steps that can use them: Exploring the use of a $Path Variable in Scripts

              • 4. Re: Open a file from container field (open storage)

                     Thank you for the information on the $Path variable. Your sample database helped immensely. I was able to get the files to export with the name they were imported with, which eliminates the duplicate filename problem. 

                     I can't thank you enough.