I've managed to get emailing working, but not the automatic attach pdf part, any ideas?
To handle the operation cleanly, you're probably going to require a script - which can be attached to your button via the Perform Script[ ] button action.
In the script, you will be able to set a variable to the path and field name for the pdf you want to generate, then enter the variable into the Specify output file dialog for a Save Records as PDF[ ] step in your script. If you want to place the file dynamically on the user's desktop or in the documents folder, you'll be able to use either Get(DesktopPath) or Get(DocumentsPath) calculation functions to supply the path in the calc that sets the variable, and simply append your desired file name.
Then, you can either enable the checkbox option in the Specify output file dialog to "Create email with file as attachment", or if you want the email sent directly via SMTP or sent silently via the user's default mail client application, you might prefer to use a subsequent script step - Send Mail[ ] - to handle the email. In that case, you will be able to pass the same variable to the Send Mail[ ] step Specify file dialog to attach the pdf to the email.
If you also want to clean up by deleting the pdf after the email has been sent, you might consider closing your script with an Export Field Contents[ ] step in which you leave the target field unspecified and enter the variable name in the Specify output file dialog. That will delete the pdf file that was created earlier in the script.
So, in all you may be looking at a script with four main steps, as follows:
Set Variable [ ]
Save Records as PDF [ ]
Send Mail [ ]
Export Field Contents [ ]
If you need to generate the pdf from a different layout (than the layout where the button resides), you'll need to add a Go to Layout [ ] step at the start and another at the end to take the user back whence they came.
R J Cologon, Ph.D.
FileMaker Certified Developer
Author, FileMaker Pro 10 Bible
NightWing Enterprises, Melbourne, Australia
Yep, the way Ray has said it is pretty much it I reckon....
Actually I didn't know about the 'Export Field Contents' step without a target field being specified to be used to delete a file - nice tip!
Craig, in case you are still a bit confused about the parts about specifying variables for the file path etc... I've attached a simple file which demonstrates what Ray was saying. However, for the emailing part, it is up to you whether you want to send directly from FileMaker using an SMTP server or using your email client to do that part.... I've set the attached example file to use your email client.
Also, you may want to improve the first script step where the $path variable is set so that the name of the file created is calculated using some other criteria or field data (e.g. invoice number) rather than the hard wired 'myfile.pdf' name I have used.
Example.fp7.zip 5.9 K
Thanks for the help, the example.fp7.zip file looks perfect and I will test it tonight!
>If you also want to clean up by deleting the pdf after the email has been sent, you might consider closing >your script with an Export Field Contents[ ] step in which you leave the target field unspecified and enter >the variable name in the Specify output file dialog. That will delete the pdf file that was created earlier in the >script.
Saving to the temporary folder is how I usually handle it. That folder empties on application exit.
Ray Cologon wrote:
Set Variable [ ]
I am a horder... so this bit is important if you want to keep your PDFs and match them to the record of the email send... particularly if you are sending email direct to a mail server...
I like to have a shared volume where all workers save their stuff to... and I use a calculated variable that determines the platform so it can choose between filemac and filewin.
Then I include the record ID and a little bit of info from the record so it is human readable.... so my variable might end up looking like this:
"filemac:/sharevolume/folder/Inv" & InvoiceNum & "_" & surname & "_" & state & ".pdf"
"...you might prefer to use a subsequent script step - Send Mail[ ] - to handle the email. In that case, you will be able to pass the same variable to the Send Mail[ ] step Specify file dialog to attach the pdf to the email."
I am using FM 13 Adv. I have been able to get all of the other items to function with the exception of the above. I have specified the file as the variable, but no attachment is created on the email. Any help you can provide would be great!
One way to troubleshoot this is to create a dummy PDF file in the location you are expecting to save this one.
Then in the Sendmail script step navigate to the file you have just saved as if you are hard coding the file into the script and add it in the attachment dialog. Then compare the path that FileMaker creates for this to the one you are creating with the variable and see if there are any differences -- which might account for why it is not working.
And just for the sake of checking, the box saying Attach File is ticked isn't it?
I found the problem.... The FMP file is on our server, not resident on my computer. When I place a copy of the FMP file on my computer and try the script again, it works. So attaching a variable, to an email, via the Send Email script step, doesn't appear to work when the FMP file is being served.
Any way around this? Server settings perhaps?
It may be a permissions issue. You have to make sure that the user, fmserver, has read/write access to the directory where you are storing the pdf files.
Did you try the filepath to the Temp folder?
FM Server has to have permissions for the target folder on the machine.
I'm technically not storing the file, since I'm using a variable, but I will research permissions, just to be sure.
what version of FM are You running?
There are so e reports about problems with 32/64bit versions of FM and Outlook. I don't have Outlook, but AFAIK FM has to be 32bit when Outlook is 32bit. Could be the issue..