14 Replies Latest reply on Feb 26, 2012 9:36 PM by TraceyLillis

    Email script to send a PDF invoice



      Email script to send a PDF invoice


      I am new to Filemaker.  I have created a file with a demographic database.  I want to send an email to each person in the database with an invoice that is customized for that individual.  I have created the invoice as a layout.  I have tried to create a script that will save the invoice as a PDF and then create an email with that PDF attached.  I understand that a "filepath" has to be created to do that and that I have to use a variable to make a temporary file into which the pdf will be placed.  The pdf then gets attached to the email.  I am not sure how to create a temporary filepath (OSX), save the pdf and retrieve it.

      Thanks for your help!

        • 1. Re: Email script to send a PDF invoice

          This method works for both Mac and Windows:

          Set Variable [$FilePath ; Value: Get ( TemporaryPath ) & "Filename.PDF"]


          • 2. Re: Email script to send a PDF invoice

            Realize you are dealing with a rookie here:

            1.  Do I write the script step exactly as you have above, or do I need to change the script specifically for my database? For instance, do I change "Filename.PDF" to "Myfilename.PDF"

            2.  Now when I script the "send email" step, what do I  put in the attachment dialogue under "specify" so that it gets attached?

            Thanks for your help!

            • 3. Re: Email script to send a PDF invoice

              1) Yes, you need to customize it to match what you need. "Filename.PDf" is just a place holder. You can use literal text in quotes here like you describe or you can write a calculation that pulls data from a field or fields in your database.

              2) Put the variable name in the Specify File dialog that opens after you click the attach file check box.

              • 4. Re: Email script to send a PDF invoice

                1. It may be that I don't understand what the "Get ( TemporaryPath ) & "Filename.PDF"]" part of this is doing.  Does it matter what goes in the "Filename.PDF" if it's a temporary file?  

                2.  When I run the script as you describe above, I can create a pdf called "filepath".  It opens in the finder. An email is created, however, the pdf is not attached to my email when I specify $filepath as the file to be attached.

                3.  Is there an easy way that I can copy the script and paste it into the post?

                Thanks for your patience.

                • 5. Re: Email script to send a PDF invoice

                  1) No, it doesn't matter as long as you are saving to the Temporary Items folder. In other locations, you must make sure that your filename doesn't match an existing file that you don't want to replace with the new PDF.

                  2) What I've found that works is to use save as PDF to create the PDF and then use Send Mail to send your email. You can use the $FilePath variable in both steps so that you first create the PDF in Temporary items and then turn around and attach the same file to your email.

                  3) You can print your script to a PDF (Needs a PDF utility or Acrobat if you are a Windows user), open the PDF and use the PDF reader's text tool to select the script text and copy it to your clipboard for pasting. If you have FileMaker Advanced, you can generate a Database Design Report and copy your script's text from the report.

                  • 6. Re: Email script to send a PDF invoice

                    I am still having problems with attaching the PDF.  I am doing it as you suggested in 2 above. 

                    I tried to print the screen to PDF, but nothing seems to happen when I press print.    I do have Acrobat, and tried to take a screen shot of the script with Acrobat, but couldn't paste it into the window. 

                    • 7. Re: Email script to send a PDF invoice

                      Did you click the Print button in Manage | Scripts? That should bring up a print dialog where you can specify printing it as a PDF. This is an option in the print dialog on Mac and with Windows systems, you need a PDF "printer" such as Adobe Acrobat (not reader) or one of the other utilities that do this.

                      1. Open the script in the script editor
                      2. Select the send mail script step and click the Specify button
                      3. At the bottom of this Send Mail dialog is a check box labeled "Attach File". Click it.
                      4. Type the exact name of your variable, $Filepath, without quotes into this Specify File Dialog.
                      5. Select or enter any other options as needed for your email to be sent successfully.

                      Also, make sure that you have an Email client program that is compatible with FileMaker. You can look this up in FileMaker help under the Send Mail step to find a list of compatible applications for your system. Make sure that you can send your email by selecting Send Mail from the File Menu and send an email to your self from FileMaker.

                      • 8. Re: Email script to send a PDF invoice
                        I did click the Print button, the print dialog appears.  I specified PDF.  When I click the Print button, nothing happens!  I do have Acrobat 9.0.  I'm not sure where to go with this next.  I think there must be something simple I'm missing here. Frustrating!
                        • 9. Re: Email script to send a PDF invoice

                          To confirm, you are clicking on the script name so that it is highlighted in Manage Scripts, then clicking the Print button at the bottom of the dialog?

                          On another note, I just spotted an error in my original expression. It should read:

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

                          • 10. Re: Email script to send a PDF invoice

                            Don - when you get this working and probably build these steps into a longer script, or chain of scripts, please double check that if you are using the same file name for the pdf every time that there is absolutely NO possibility of a script being interrupted (either by a crash, bug, or user action) in a way that will lead to the next running of the script picking up the existing pdf, say.  Can be very embarrassing if one customer receives another's invoice.

                            Okay: I'm paranoid.

                            • 11. Re: Email script to send a PDF invoice

                              Still can't get the script to print to PDF.  I get the print dialogue box, have selected Adobe PDF 9.0 as the printer and when I push the print button nothing happens.  Also, nothing happens when I try to save it as a PDF in the dropdown PDF menu below.  No further dialogue boxes appear.

                               Is there another way to copy the script?

                              • 12. Re: Email script to send a PDF invoice

                                I mentioned a second option, but it requires FileMaker Advanced. Others simply capture a screen shot and upload it.

                                Don't try to use the print or save as PDF options in the File Menu for creating a PDF of your script:

                                1. Select Manage | Scripts....
                                2. Click the script's name in this dialog to highlight it.
                                3. Click the button with the printer icon in the bottom of this dialog.
                                4. Select your PDF printer to print the script.
                                • 13. Re: Email script to send a PDF invoice

                                  Actually I did use a script at all. I wasted more time to do that. I would recommend not putting anything in the source and leave it blank. The button should be using the button setup "save Record as pdf" and then make sure you have no scripts (or nothing in the output file path - this will allow customization in how everyone is saving their documents) in the specify output file but check the create "e-mail as attachment." In the specify options just choose "current record".

                                  That should do it.

                                  • 14. Re: Email script to send a PDF invoice

                                    I am trying to do a similar task.  I have layouts I want saved as PDF's and email to clients (1 record per client).  I am currently using Windows 7, and the database is loaded onto a FMP Server. 

                                    My script looks like the following attached image.  It gives me the following error when trying to save (I am assuming) the file to the temporary path "Student_email.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"

                                    When I choose OK, it opens my Outlook email, however there is no attachment. 

                                    Can you please advise where I am going wrong, or is there a special way when using a FMP Server?