5 Replies Latest reply on May 31, 2013 7:41 PM by appt

    Script an Email Message with PDF of Layout



      Script an Email Message with PDF of Layout


      This is probably a simple one, but I'm stubbing my toe on it nonetheless.


      I need to do a simple script to switch from an entry layout "A" (with buttons and colors) to a layout "B" arranged for printing (no background, colors, etc.). Once script is at "B" create an email message with the customer's email address, a standard subject line and the "body" of the email message as a PDF image of layout "B" (i.e. the invoice). Sounds simple enough.


      An additional issue is how to design the script to support several users on a LAN using this solution. 


      So far, I believe I have two general approaches I could use. I could be using the "Send Mail" script step or the "Save Records as PDF" with the auto-create email option (with file as attachment).


      The second approach does create the email OK but without the email address of the customer. The first approach creates the PDF file to be attached and allows me to insert the email address of the customer into the email message, but leads me into the need to provide a FILE PATH to support ALL users on the LAN for the PDF of the invoice layout itself, the vagaries of which I've never been able to put into plain English from the FM help file explanation of file paths. I get confused by the "absolute", "local", "relative", "network" terminology and the examples given in the help file don't make any sense to me. Best way I can put what I'm trying to do into "file path language" is is to say I need a file path for the PDF image file of the invoice being created that is INDIVIDUALIZE and will allow any and all users on the LAN to create an email with JUST that PDF image file as the body of the email message going out.


      Any thoughts on this would be appreciated. 

        • 1. Re: Script an Email Message with PDF of Layout

          Hi RayMentor


          The best way to go about this is to use both the Send Mail script step and the Save Record as PDF, but without the auto-create e-mail option checked. And control the path of the PDF for both creating it and attaching it to the email using a Variable.


          This particular script will store the PDF in a Temporary Folder that will be cleared out when the machine is restarted, this will mean anyone on the network can use it without affecting each other, but you can point it to a location on your network if you want to store the PDF's. Also if you are using a Windows machine then change "filemac:" in the Variable to "filewin:", and you can also calculate the file name based on a field in the record if you require.


          The script will look like this:


          Got to Layout ["LayoutB"] 
          Set Variable [$FilePath ; "filemac:" & Get ( TemporaryPath ) & "FileName.pdf"]
          Save Record as PDF [No dialog; "$FilePath", Current record]
          #PDF has been created in the Temporary folder, now attach and send in email
          Send Mail [To: $Email ; subject: ... ; "$FilePath"]
          Got to Layout ["LayoutA"] 


          You will setup the Send Email script step as you did previously except when you click 'Specify...' for the Attachment you will input "$FilePath" as this will be the location the PDF was created.


          And this should do the trick, do ask if anything in unclear.


          I hope this help. 

          • 2. Re: Script an Email Message with PDF of Layout
               Orlando, you're a bon to mankind! I adapted the script you kindly offered and it works like a champ. Many thanks. Ironically, I discovered your earlier post to someone who had a similiar need and was in the process of adapting the script you offered to him when I got your reply in this thread. Very glad you're generous with sharing your expertise.
            • 3. Re: Script an Email Message with PDF of Layout
                 NO worries RayMentor, glad it all worked for you.
              • 4. Re: Script an Email Message with PDF of Layout

                     Hello RayMentor!

                     I did use the script  and it did work xcelent, but.... i use a portable + windows xp on the street and the FM12 file reside on my place in a Mac.  How should be the scrip to work from the XP, because from there it does not work, I got a msg "$FilePath.pdf" can't be used and I need the extension travel with de filename. I write to you from Montevideo, Uruguay. Thanks in advance for your help! Regards Alvaro.

                • 5. Re: Script an Email Message with PDF of Layout


                       total newb at this. Am using Filemaker 12 and have tried recreating the code above, however when I run it it gives an error message as follows

                       “Filename.pdf” could not be created on this disk.  Use a different name, make more room on the disk, unlock it or use a different disk.

                       Any clues as to what I am doing wrong.

                       I am using this to create a record of individual student progress and would like to be able to email the particular layout to parents.