There comes a time in every FileMaker developer’s life when she needs to export a file temporarily. Maybe you’re exporting records only to import them right back in again later. Or perhaps your creating a PDF file that you only want to email to someone.
And with this need comes an eternal question: Where should you put it?
Finally, in FileMaker 9, we have an answer.
In fact, every modern operating system provides a perfect place for this sort of thing: The so-called “temp folder.” This special folder has a few special powers that make it an ideal candidate:
- It is always there, so you never have to worry that your user might not have one.
- A user on the computer can always write to his temp folder. There’s no need to stress about permissions problems. Also, the temp folder can’t be seen by any other user, so it’s secure.
- Best of all, files in the temp folder are automatically deleted whenever the computer restarts.
The temp folder is nothing new. It’s been right there on your Windows or Mac OS X computer from the very beginning. But it isn’t always in the same place, and it can be tough to find inside a FileMaker script.
FileMaker 9 works around this problem with a new calculation function: Get(TemporaryPath). This function figures out where the best temp folder is on the computer FileMaker’s running on and returns its path, ready to use in a variable-based export.
Here’s an example. Normally, you can’t “open” a file stored in a container field. FileMaker only lets you open the file directly if you’ve stored a reference to the file in the container. Here’s a script that works around this limitation. It exports the file to the temp folder, then imports a reference to it into a global. Finally, it tells FileMaker to open the temporary file. export the contents of a container field to the temp folder on any computer:
Set Variable [ $path; Get(TemporaryPath) & "my_temporary_file.jpg" ]
Export Field Content [ My Container Field; $path ]
Insert File [ Reference; My Global Container, $path ]
Go to Field [ Select/perform; My Global Container ]


George D. Appel
8-4-2007
Great idea! However, I don’t know what to use for “Insert File” in FMP 9 Advanced.
Thank you for your tips and help.
Dom
8-7-2007
Thanks for this tip, but how can I give to the temporary file name the same file extension of the file I wish to open.
For example if I have several containers with different kind of files types (pdf, word, etc…) the temporary file should have the same file extension .pdf or .doc as the original file so that it opens in the right application.
Thanks in advance for your help.
Geoff Coffey
8-8-2007
@dom: I’m going to apply two little-known calculation tricks to get your answer.
First, when you use a container field in a text-like way, and the field contains a file, you get the name of the original file. For example, if you have a container field called
Documentand you make a calculated text field with this formula:GetAsText(Document)you’ll see the name of the original document in the field.Second, the
Positionfunction can search from the end of a text value if you set the start to-1So here is a formula that gets the file extension of the file stored in a container field:
This will only work if the file is stored in the field. If you store only a reference to the file, you can use a similar technique. In your data viewer, use
GetAsTextto see what FileMaker reports about the reference to the file, and write a calculation to parse it as appropriate.Hope this helps.
Dom
8-11-2007
Thanks !
With the
GetAsTextfunction it works perfectly1 Table “files”
1 container field “container1″
1 container field “global_container”
and here is the script:
Homer
9-24-2007
I’ve had some issues with the Get(TemporaryPath) Function.
It was my understanding that this dir was “temporary” meaning the documents I export to this dir would be deleted at shut down. I have not found this to be the case.
In order to have files removed (and thats at FMP startup not shutdown), I have had to preface the filename with the string FMTEMPFM. This seems to indicate to FM that this is a true temp file.
I haven’t seen any documentation on any of this and was looking for additional insight.
Geoff Coffey
9-25-2007
@homer: I had the same misconception you had. I thought this temp folder was emptied on reboot, just like the
/tmpfolder on a typical unix-ish system. But in my more recent testing, it does not actually empty automatically. Apparently it is our job to delete the file when we’re done.I have not discovered the FMTEMPFM thing you mention. If that works it is a great tip. I’ll play with it and see what I discover.
Otherwise, it is possible to delete files in FileMaker without a plug-in. You just have to get an empty found set:
Then do an export. When you do the export, if the file you target already exists it will be deleted. And since there’s nothing to export, no new file will be created. This is a hack, and may certainly stop working in a future version of filemaker, so a sanctioned technique would be much better.
Thanks for the tip.
Robert Gosney
10-3-2007
I have had a similar issue with variable that are available during a script, and allow for all sorts of data comparisons, but in the end, if I have a result of a calculation that can only be addressed with a Variable, I’m stuck with it, as I can find no way to store a Variable to a field in a table ($VariableName). Is there some way to store these Variables?
Thanks,
Bob
Geoff Coffey
10-6-2007
@Bob: I may be misinterpreting your question, but you can put a variable value into a field using the
Set Fieldscript step:Does that help?
Robert Gosney
10-8-2007
Geoff,
Thanks. That’s the answer. I’ve been a programmer since 1982, and my company has just purchased Filemaker Server and the Clients. I now have to “re-educate” myself! This is a whole different world from PHP, or C++. Thanks for the help.
My next great discovery will be to find the function that “flags” when the contents of a field have been changed in a table. I believe that there is a function out there in Filemaker for this, just don’t know where.
Thanks again!
Bob
dontoon
5-21-2008
As always, there are many ways to achieve the same results in FileMaker. I just create 2 container fields, “file,” and “fileref.” Then Insert File is a scripted button where first a reference is stored in “fileref,” than a variable GetAsText grabs the filepath, and uses it to insert the actual file in “file.” Now you can have both the benefits of having the actual file, and that of opening the file using the techniques described above.