5 Replies Latest reply on Oct 31, 2013 1:20 PM by stam66

    Help with script to create and email a PDF of a record

    KimSingleton

      Title

      Help with script to create and email a PDF of a record

      Post

           This is the script that I have written but it doesn't work frown

           Any help would be appreciated - 

            

            

      If [ Get ( SystemPlatform ) = 3 ]
      Set Variable [ $FileName; Value:Clients::C_FirstName & Sessions::Ses_Date ]

      Save Records as PDF [ File Name: “$FileName”; Current record ]
                [
      Document - Compatibility: Acrobat 7 and later ]
                [
      Pages - Number Pages From: 1; Include: All pages ]
                [
      Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Pages Panel and Page; Page Layout: Single Page; Magnification: 100% ]

      [ Restore; No dialog ]

      Set Variable [ $PDFPath; Value:Get ( DocumentsPath ) & $FileName ]

      Send Mail [ Send via E-mail Client; To: Clients::C_Email; CC: Locations::Loc_Email; Subject: Clients::C_FirstName & " " & Sessions::Ses_Date; Attachment: “$PDFPath” ]

      End If 

            

        • 1. Re: Help with script to create and email a PDF of a record
          johnswhitehead_1

               I struggled with this for a while but have got it working on both the Mac and the iPad. The only difference between your settings and mine is that I use the Get ( TemproraryPath ) command, rather than Get ( Document Path ). This might make a difference.

          • 2. Re: Help with script to create and email a PDF of a record
            TSGal

                 Kim Singleton:

                 Thank you for your post.

                 You should include the file extension ".pdf" within your script so the attachment can be recognized as a PDF file.  Therefore, try the following:

                 If [ Get ( SystemPlatform ) = 3 )

                    Set Variable [ $FileName ; Value: Clients::C_FirstName & Sessions::Ses_Date & ".pdf" ]
                    Save Records as PDF [ No dialog ; "$FileName" ; Current record ]
                    Set Variable [ $PDFPath ; Value: Get (DocumentsPath) & $FileName ]
                    Send Mail [ Send via E-mail Client ; To: Clients::C_Email; CC: LOcations::Loc_Email; Subject: Clients::C_FirstName & " " & Sessions::Ses_Date; Attachment: "$PDFPath" ]

                 End If

                 -----

                 If Sessions::Ses_Date is a Date field, it may be formatted as MM/DD/YYYY.  Since slash (/) characters are not recognized in file names on an iOS device, you would need to substitute slashes for underscores or hyphens.  If this is the case, change the "Set Variable" step above to:

                 Set Variable [ $FileName ; Value: Clients::C_FirstName & Substitute ( Sessions::Ses_Date ; "/" ; "_" ) & ".pdf" ]

                 Keep me updated with any progress.

                 TSGal
                 FileMaker, Inc.

            • 3. Re: Help with script to create and email a PDF of a record
              KimSingleton

                   I am still stuggling with this - The script creates the email as I wanted but the pdf is not attached - any ideas?

                   thanks, Kim

              • 4. Re: Help with script to create and email a PDF of a record
                TSGal

                     Kim Singleton:

                     Let's take it one step at a time.  Does the PDF file get created?  That is, when you return to the FileMaker Go home screen, is the PDF file listed?

                     Start simply by changing $FileName to a static result, like "Test.pdf".  If this works, then try using the field name.  If that works, then try adding the Substitute function with the Date field.  Any other information you can provide would help pinpoint why the file isn't being sent.

                     TSGal
                     FileMaker, Inc.

                • 5. Re: Help with script to create and email a PDF of a record
                  stam66

                       Exact same problems here... I pretty much used an identical approach to the one above.

                       It kept complaining about failing to send mail, or (when SSL was on) that there was a problem with SSL, which wasn't helpful.

                       I found this great tool to help diagnose connection problems with FileMaker / SMTP, download the .fp7 file (works fine with FMP12 after conversion) from here: http://www.savvydata.com/blog/2009/11/fixing-smtp-send-mail-error-1506/

                       After seeing that all connections were being rejected on/off SSL, with/without passwords of various kinds, i set the SSL to 'on' and changed port to 465 using 'clear' password... that DID send an email. One caveat: On OSX, the FMP solution needs to be in the 'Documents' folder for this solution to send via SMTP - otherwise an empty message gets sent and it launches the mail client with an empty email as well, but with the attachment bizarrely enough.

                       So now i have a working solution (i.e. it sends the mail, addressees are correct and the attachment is attached), but it STILL launches my mail client created a message with the pdf attachment but otherwise empty... Any suggestions how i can suppress the mail client?

                       many thanks

                       Stam