1 2 Previous Next 15 Replies Latest reply on May 1, 2016 8:39 PM by Steelers1

    How to Script "print to pdf" and "email"?

    filemaker2012

      Hi,

       

      This is probably too simple for this forum, so feel free to point me to documentation if available?

       

      I've made a simple Filemaker 11 Pro quote/invoice database and I'd like to set it up so the user can simply;

      1) Press "invoice" and have the email address read from a field

      2) Have the "invoice" print to PDF and then automatically attached to the email

      3) Send the email and return to the original page.

       

      I've managed to get emailing working, but not the automatic attach pdf part, any ideas?

       

      Regards,


      Craig

        • 1. Re: How to Script "print to pdf" and "email"?
          RayCologon

          filemaker2012 wrote:

          I've managed to get emailing working, but not the automatic attach pdf part, any ideas?

           

          Hi Craig,

           

          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.

           

          Regards,

          Ray

          ------------------------------------------------

          R J Cologon, Ph.D.

          FileMaker Certified Developer

          Author, FileMaker Pro 10 Bible

          NightWing Enterprises, Melbourne, Australia

          http://www.nightwingenterprises.com

          ------------------------------------------------

          • 2. Re: How to Script "print to pdf" and "email"?
            skywillmott

            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.

             

            cheers,

             

            Sky.

            • 3. Re: How to Script "print to pdf" and "email"?
              filemaker2012

              Thanks for the help, the example.fp7.zip file looks perfect and I will test it tonight!

              • 4. Re: How to Script "print to pdf" and "email"?
                DavidJondreau

                >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.

                 

                Neat trick!

                 

                Saving to the temporary folder is how I usually handle it. That folder empties on application exit.

                • 5. Re: How to Script "print to pdf" and "email"?
                  LyndsayHowarth


                  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"

                   

                  - Lyndsay

                  • 6. Re: How to Script "print to pdf" and "email"?
                    beekersc

                    RayCologon wrote:

                    "...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!

                    --

                    Sheree

                    • 7. Re: How to Script "print to pdf" and "email"?
                      jrenfrew

                      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?

                      • 8. Re: How to Script "print to pdf" and "email"?
                        beekersc

                        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?

                        --

                        Sheree

                        • 9. Re: How to Script "print to pdf" and "email"?
                          keywords

                          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.

                          • 10. Re: How to Script "print to pdf" and "email"?
                            Stephen Huston

                            Did you try the filepath to the Temp folder?

                            FM Server has to have permissions for the target folder on the machine.

                            • 11. Re: How to Script "print to pdf" and "email"?
                              beekersc

                              I'm technically not storing the file, since I'm using a variable, but I will research permissions, just to be sure.

                              --

                              Sheree

                              • 12. Re: How to Script "print to pdf" and "email"?
                                Steelers1

                                I keep receiving an error that appears to be coming from my email client when using the Send Mail script step using my email client. It states:

                                 

                                ErrorMessage.png

                                 

                                Any ideas what may be causing this? And even better how to avoid it?

                                • 13. Re: How to Script "print to pdf" and "email"?
                                  Steelers1

                                  I keep receiving an error that appears to be coming from my email client when using the Send Mail script step using my email client. It states:

                                   

                                  ErrorMessage.png

                                   

                                  Any ideas what may be causing this? And even better how to avoid it?

                                  • 14. Re: How to Script "print to pdf" and "email"?
                                    Markus Schneider

                                    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..

                                    1 2 Previous Next