How to create and preserve a PDF in FileMaker and then email it....via the server.

So you're using FileMaker 17 and you want to generate a PDF, then store it in a container field and, finally, email the PDF from within FileMaker? That's easy, it's just a Save Records as PDF script step, followed by a Send Mail step and then Insert File.

But....you'd really like to do all of this via FileMaker Server? Only problem is that FileMaker Server doesn't support Insert File script steps and you really REALLY want to use the server....bugger.

Okay, it's still doable using an Insert from URL script step instead of the unsupported Insert File. But then you've still got the problem of working out what the file path should be and is it different for Macs and PCs? Worry not, I've done the donkey work for you right here.

You might be interested in doing this from a number of different angles. For example, you may already have the file / PDF or you might need to create it first. Perhaps you don't want to preserve the PDF in a record. Lots of options. I'm going to take the stance that you want to do it all - for those who don't, just strip out the parts that aren't of any interest to you.

 

Create the PDF

First off, you'll need to use the Save Records as PDF script step on the record(s) / layout you want to preserve. You'll then need get the file path as we understand it and adjust it so that it'll work with the Insert from URL script step.

$File is the full path to your file, including the filename. I'm using the Temporary Folder here as it's arguably the best place for temporary files.

Set Variable [ $File ; Value: " Get ( TemporaryPath ) & "Your File Name Here.PDF" ]

eg Set Variable [ $File ; Value: " Get ( TemporaryPath ) & "CustomerQuote.PDF" ]

$FileURL will be an adjusted version of of $File; one which the Insert from URL script step will understand.

For a Windows PC

Set Variable [ $FileURL ; Value: " "file:/" & File ]

For Mac OS

Set Variable [ $FileURL ; Value: " "file:/volumes" & File ]

 

Preserve the PDF

Right, head over to the layout where you're keeping your PDFs - I prefer to use a File table to store all of my files (be they PDFs or graphics used in the user interface) since you get so much more control if all of your container fields are in one place.

Go to Layout [ "Your Layout Here" ; Animation: None ]

eg Go to Layout [ "Dev : File" ; Animation: None ]

New Record/Request

Insert from URL [ Select ; With dialog: Off ; "Your table field here" ; $FileURL ]

eg Insert from URL [ Select ; With dialog: Off ; File::File ; $FileURL ]

NB You might want to use a Set Field step here to record what this new record relates to (eg a Customer ID) and after all that, you'll probably need to close the window down / navigate to your original layout. You can work that out - I'm not doing everything here!

 

Email the PDF

Now it's just a Send Mail script step, making sure that you attach the PDF using $File (not $FileURL).

eg Send Mail [ Send via SMTP Server ; No Dialog ; To: $Email ; Subject: $Subject ; Message: $Body ; "$File" ]

No doubt you'll have a different email address / subject / body so you'll need to make any necessary changes there (not to mention setting the SMTP email account details).

 

Rightio! I hope that's helped you out! If it hasn't and you're after some FileMaker database development work, igeek are here to help!


Blog entry is closed for new comments.