2 Replies Latest reply on Aug 24, 2012 3:42 PM by CameronL.

    Emailing / attaching a generated PDF

    CameronL.

      Title

      Emailing / attaching a generated PDF

      Post

      Hi all.

      I'm running into a problem trying to run a script to dynamically generate a PDF of a list of records in an Invoice layout, and create an email with that PF automatically attached. Here's my script:

      If [Get ( SystemPlatform ) = 3]
           Go to Related Record [Show only related records; From table: "Measures_Add_Products"; Using layout: "HD Measure" (Measures_Add_Products); New window]
           # Set page count
           Go to Record/Request/Page [Last]
           Set Field [Measures_Add_Products::Page Count; Get ( Page Number )]
           Go to Record/Request/Page [First]
           #
           Set Variable [$FileName; Value:"Measure PO# " & Measures::PO# & " - " & Customers::NameFull_LastFirst & ".pdf"]
           Save Records as PDF [Restore; No dialog; "$FileName"; Records being browsed]
           Set Variable [$PDFPath; Value:Get ( DocumentsPath ) & $FileName]
           Send Mail [Send via E-mail Client; Subject: $FileName; Message: "Here's your invoice"; "$PDFPath"]
      Else
           Go to Related Record [Show only related records; From table: "Measures_Add_Products"; Using layout: "HD Measure" (Measures_Add_Products); New window]
           # Set Page Count
      Enter Preview Mode []
           Go to Record/Request/Page [Last]
           Set Field [Measures_Add_Products::Page Count; Get ( Page Number )]
           Go to Record/Request/Page [First]
           #
           Set Variable [$FileName; Value:"Measure PO# " & Measures::PO# & " - " & Customers::NameFull_LastFirst]
           Save Records as PDF [Restore; No dialog; "$FileName"; Records being browsed]
           Set Variable [$PDFPath; Value:Get ( TemporaryPath ) & $FileName]
           Send Mail [Send via E-mail Client; Subject: $FileName; Message: "Here's your invoice"; "$PDFPath"]
      End If
       

      The script is written to detect whether the user is using FileMaker Pro on the computer or FileMaker Go on the iPad, and makes a couple minor file path and file extension changes. I've highlighted the differences in the If/Else statement in blue.

      The script works fine in Filemaker Go on the iPad but does not work on Filemaker Pro on my Mac.

      Does anyone have any idea what I'm doing wrong here? Help is greatly appreciated.

      Thanks!

        • 1. Re: Emailing / attaching a generated PDF
          philmodjunk

          The file path to which you are saving your PDF is not the same as the one you use to attach the PDF to the email.

          The lines that include the references to the documents path and the temporary path should come before the save as PDF steps.

          • 2. Re: Emailing / attaching a generated PDF
            CameronL.

            You're right. I was setting the Save Records as PDF output path as $FileName .. probably because I'm used to thinking of titling a file when you save it. The problem was making sure that the output path was the TemporaryPath. So that's now changed and fixed.

            There was some additional confusion because the iOS version of the script worked fine, even using $FileName as the output path. I believe that must have to do with the way iOS saves documents in its DocumentsPath.

            Either way it's fixed for the Mac now. Thanks again for the help :D

            Here's the changed part of the script below for anyone's reference:


            Set Variable [$FileName; Value:"Measure PO# " & Measures::PO# & " - " & Customers::NameFull_LastFirst & ".pdf"
            Set Variable [$PDFPath; Value:Get ( TemporaryPath ) & $FileName] 
            Save Records as PDF [Restore; No dialog; "$PDFPath"; Records being browsed] 
            Send Mail [Send via E-mail Client; Subject: $FileName; Message: "Here's your invoice"; "$PDFPath"]