-
03-19-2010 04:53 PM #1Guest Member
- Join Date
- Jul 2009
- Posts
- 61
- Location:
- Los Angeles
- FM Version
- 10
- Skill Level
- Novice
- OS
- Windows
- Rep Power
- 0
Create pdf and send it as an email
I'm trying to script something that will allow a user to automatically make a report, save it as a pdf then send it off as an email with attachment
I'm a little fuzzy on the file attachment and email part, mostly because I'm a bit unsure about the file paths.
Can I make the pdf and attach it as an email then send it out without having to actually make and save the pdf on the computer?
If not: Because I'm unfortunately working with both mac and pc users is it possible to have the pdf save to the server and then send it from there?
-
03-19-2010 05:13 PM #2Moderator - Editor
- Join Date
- Sep 2007
- Posts
- 2,014
- Blog Entries
- 8
- Location:
- New Zealand
- FM Version
- 8,9,10 and now 11 certified.
- Skill Level
- Developer
- OS
- Mac
- Rep Power
- 39
Re: Create pdf and send it as an email
There are a few options available for sending email. First, the "Save as PDF" script step has a tickbox option on it to automatically attach the saved PDF to a new email message. This will use the users default email client to open up a new message and attach the PDF. For this step you would still require to save path - tho it's not as tricky as it sounds.
Save as PDF option is also available via the Status Area, and the File-> save/send records as menu. This is not scripted method, but if users used these options to access the PDF, they could tick the "Automatically send as email" option themselves in addition to being able to save the report as a PDF wherever they wanted to on disk.
-----
For the scripting you will have to save it to a location on disk via the Save records as PDF script step. To do this you'll need to setup a path into a local variable in your script, so that when you save the PDF, you can save it to the variable, ie $Path.
When the PDF is saved to $Path, you have two options as to how you send the email. First, is to tick the "automatically create email" option on the save records as PDF step, so when the PDF is saved, it will automatically be attached to a new email that will launch in the users email client.
The other option is to use the "Send Mail" script step, and within that, set $Path as the attachment under the attachment option. Send Mail step allows you to either launch the email in the users email application, or send it direct from FileMaker providing you know the correct smtp server details to send from. With this step you can also define what the from/to/subject/message are as defaults...
-----
Now, onto setting $Path. It's not as hard as you might think - even when users are cross platform.
the first part of a path will be either "filemac:" or "filewin:" depending on the users operating system. There is a function you can use to determine what operating system a user is on, and it is called "Get (SystemPlatform)" This function returns a number which corresponds to the operating system the user is using.
The numbers are:
-1 if the current platform is PowerPC-based Macs
1 if the current platform is Intel-based Macs
-2 if the platform is Windows XP or Windows Vista
So to use this, you can do something like the following to determine the start of the path:
If ( Abs ( Get ( SystemPlatform ) ) = 1 ; "filemac:" ; "filewin:" )
If the absolute value of the system platform is 1, it's a mac, otherwise it's windows.
With that done, you need to determine a generic location on the computer that will work for both windows and mac. For this purpose you can also use a special function called Get(TemporaryPath). This will return the location of the temporary items folder on either mac/pc. This is a good place to store the PDF because firstly it's out of the way of the user, secondly this folder is periodically cleaned up by the operating system, and thirdly it's a known location we can access on both platforms.
The final part of the Path is the name of the PDF you want to use, and that's fairly straighforward.
So, in putting it all together you could try something like:
If ( Abs ( Get ( SystemPlatform ) ) = 1 ; "filemac:" ; "filewin:" ) & Get ( TemporaryPath ) & "MyReport.pdf"
When that is evaluated, you should end up with a nice looking path that you can use to put into $Path and save your PDF there. Once it is in $Path, you just need to use $Path later on in the script wherever you need it.
Good luck.
-
03-19-2010 05:43 PM #3Guest Member
- Join Date
- Jul 2009
- Posts
- 61
- Location:
- Los Angeles
- FM Version
- 10
- Skill Level
- Novice
- OS
- Windows
- Rep Power
- 0
Re: Create pdf and send it as an email
In my gut I feel it's a bad idea; would it be wrong to just use something like Get (FileMakerPath) and have the files save there? Would that even work?
-
03-19-2010 05:48 PM #4Moderator - Editor
- Join Date
- Sep 2007
- Posts
- 2,014
- Blog Entries
- 8
- Location:
- New Zealand
- FM Version
- 8,9,10 and now 11 certified.
- Skill Level
- Developer
- OS
- Mac
- Rep Power
- 39
Re: Create pdf and send it as an email
Well, it may work but I wouldn't recommend it. If the user does not have write access to the FileMaker application folder, this will fail. The reason temporary path is a better one to use is because you are guaranteed users are able to write the PDf to that folder. Sometimes users may not have access to the filemaker application folder, if they have restricted access via the operating system, or if they are accessing FileMaker application over a shared volume etc.. Is there any reason in particular why you would need to use the filemaker path over the temporary folder path? Surely if this is purely for the purpose of attaching the PDF to an email, then temporary path is fine. If you actually want to save the PDF somewhere the user can access later on disk, then maybe it's not the best location, but I gathered it was for email only.
-
03-19-2010 05:51 PM #5Guest Member
- Join Date
- Jul 2009
- Posts
- 61
- Location:
- Los Angeles
- FM Version
- 10
- Skill Level
- Novice
- OS
- Windows
- Rep Power
- 0
Re: Create pdf and send it as an email
No, that seems better. I just need to work a little more on my reading skills. Thanks
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads - The answer to your question may be in one of these posts!
-
send email to addess in email field
By bassmant in forum FileMaker Pro 9Replies: 8Last Post: 01-29-2008, 02:38 PM -
Email button works but email itself won't send
By cschmitz in forum FileMaker and E-mailReplies: 1Last Post: 05-18-2006, 06:00 AM -
Create New Mail Message / Send Event
By DataChris in forum FileMaker Pro 7.0Replies: 5Last Post: 08-17-2005, 12:21 AM -
Send email - Bcc
By damon in forum FileMaker Pro Versions 5 & 6Replies: 3Last Post: 01-10-2003, 09:14 PM -
Send email - Bcc
By damon in forum FileMaker OutputReplies: 3Last Post: 01-10-2003, 09:14 PM

























































Reply With Quote

Bookmarks