12 Replies Latest reply on Mar 18, 2014 1:32 PM by msbertrand

    Scripting a save as PDF and send Email for Local and Remote files

    brian.curran

      Hi,

      I have a script that generates a PDF from a report layout, saves it to my desktop, attaches it to an email and then deletes the file from my desktop.

       

      It all works great from my Macbook when the db file is saved locally but when I try it from the remotely hosted file, the file does not attach to the email Also, a colleague who is using a Windows PC receives an error about 'not being able to save to this location' etc.

       

      I'm assuming that I've missed out some cross-platform tweak and I probably have the file path set incorrectly. My script is as follows:

       

      Enter Browse Mode

      Go to Layout [ “IncidentsARReport” (Incidents) ]

      Print Setup [ Orientation: Portrait; Paper size: 8.26" x 11.69" ] [ Restore; No dialog ]

      #

      Set Variable [ $Platform; Value:Case ( PatternCount ( Get ( SystemPlatform ) ; 1 ) ; "filemac:" ; "filewin:" ) ]

      Set Variable [ $FileName; Value:Substitute ( Site::SiteName ; [" " ; ""] ; ["&" ; "And"] ; ["(" ; ""] ; [")" ; ""] ; ["/" ; ""] ; ["" ; "] ; ["'" ; "] ; ["" ; ""] ; [":" ; ""] ; ["+" ; ""] ; ["@" ; "at"] ; ["|" ; ""] ; ["=" ; ""] ; ["-" ; ""] ; ["," ; ""] ; ["." ; ""] ) & "_" & Substitute ( Incidents:: _cIncidentNo ; ["/" ; "-"] ; [":" ; "" ] ) & ".pdf" ]

      Set Variable [ $Path; Value:"file:" & Get ( DesktopPath ) & $filename ]
      #
      Set Variable [ $Subject; Value:Incidents::IncidentType & " - " & Site::SiteName ]

      Set Variable [ $IncidentType; Value:Incidents::IncidentType ]
      Set Variable [ $IncidentNo; Value:Incidents::_cIncidentNo ]

      Save Records as PDF [ File Name: “file:$FileName”; Current record ]
      [
      Document - Title: ""; Subject: ""; Author: ""; 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 ] #

      • // Show Custom Dialog [ Message: $platform; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
      • // Show Custom Dialog [ Message: $filename; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
      • // Show Custom Dialog [ Message: $path; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
      • // Show Custom Dialog [ Message: $Subject; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
      • // Show Custom Dialog [ Message: $IncidentType; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
      • // Show Custom Dialog [ Message: $IncidentNo; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]

        #

        Set Variable [ $SiteID; Value:"==" & Incidents::_kfSiteID ]

        Go to Layout [ “People” (People) ]
        Enter Find Mode [ ]
        Set Field [ _JoinPeopleSite 2::_kfSiteID; $SiteID ]

        Set Field [ _JoinPeopleSite 2::Role; "Incidents" ]

        Perform Find [ ]

        #

        Send Mail [ Send via E-mail Client; To: People::WorkEmail (collect addresses); BCC: ""; Subject: $Subject; Message: "* PRIVATE & CONFIDENTIAL *"

        & ¶ & "Please open the attached file to view your " & $IncidentType & " report." & ¶ & "Our Reference: " & $IncidentNo

        & ¶ & ¶ & "The attached file is in Adobe Acrobat format so you will need the Acrobat Reader in order to view its contents. Please visit http://www.adobe.com/products/acrobat/readstep.html to download a free version of the software."

        & ¶ & ¶ & "Kind regards"
        & ¶ & ""

        & ¶ & ¶ & "This e-mail is intended solely for the addressee. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately and permanently delete it.
        Unless otherwise expressly agreed by the sender of this email, this communication may contain confidential information and may also in certain circumstances be subject to applicable legal privilege. This information may not be used or disclosed except for the purpose for which it has been sent."; Attachment:
        “file:$FileName” ]

        Export Field Contents [ “file:$FileName” ]

        Go to Layout [ “Incidents” (Incidents) ]
        #
        Exit Script [ ]

       

      I would value some advice on the above script, apologies for the length of it but thought it best to include the full script just in case I am missing something obvious.

       

      Thanks

      Brian.