Page 1 of 1

Scheduled Script to export a report to PDF file

PostPosted: Thu Nov 06, 2008 10:10 am
by Mike.Sheen
Here's a little scheduled script which generates a report and exports it to a PDF on the filesystem.

Our sample scripts deployed with demo data show how to email a report, and from time to time people ask how to just dump it out to a file.

To try this out, follow these simple steps (in demo data)...

1. Create a new scheduled script, give it a name
2. Paste in the code below into the Script field
3. On the Credentials tab, enter in the details of an authorised Jiwa user and SQL credentials (if you're on a standard install, just use Admin and the JiwaUser)
4. Save
5. Choose the "Execute Now" menu option from the Record menu. It should produce a file : "C:\Test.PDF"

Code: Select all
ReportPathAndFileName = "C:\Program Files\Jiwa Financials\Jiwa\Reports\Standard\SOINF080 - BackOrders And Outstanding Orders.rpt"
Set SystemProfile = CreateObject("JiwaSysProfile.clsSysProfile")
Set PrintReportObject = CreateObject("JiwaPrintReport.clsJiwaPrintReport")
Set PrintReportObject.Database = JiwaDatabaseObject
Set PrintReportObject.JiwaCommLib = JiwaCommonLibObject
Set PrintReportObject.JLib = JiwaLibObject

Set myFSO = CreateObject("Scripting.FileSystemObject")

If myFSO.FileExists(JiwaDatabaseObject.IniFile) = True Then
   If SystemProfile.Load(JiwaDatabaseObject.IniFile) = False Then
      rtnErrorModule = SystemProfile.ErrorModule
      rtnErrorString = SystemProfile.ErrorMessage
      Exit Sub
   End If
End If

Set PrintReportObject.SystemProfile = SystemProfile
PrintReportObject.ClearError

PrintReportObject.SetUp
If PrintReportObject.ErrorString <> "" Then
   rtnErrorModule = PrintReportObject.ErrorModule
   rtnErrorString = PrintReportObject.ErrorString
   Exit Sub
Else
   If PrintReportObject.LoadReport(ReportPathAndFileName) = 0 Then
      rtnErrorModule = PrintReportObject.ErrorModule
      rtnErrorString = PrintReportObject.ErrorString
      Exit Sub
   Else
      If PrintReportObject.UpdateReport = 0 Then   
         rtnErrorModule = PrintReportObject.ErrorModule
         rtnErrorString = PrintReportObject.ErrorString
         Exit Sub
      Else
         PrintReportObject.CrystalReportObject.ExportOptions.FormatType = 31 ' crEFTPortableDocFormat
         PrintReportObject.CrystalReportObject.ExportOptions.DestinationType = 1 ' crEDTDiskFile
          PrintReportObject.CrystalReportObject.ExportOptions.DiskFileName = "C:\test.pdf"
         
          PrintReportObject.CrystalReportObject.Export False
         
      End If
   End If
End If

PrintReportObject.Cleanup
Set PrintReportObject = Nothing
Set myFSO = Nothing
SystemProfile.Cleanup
Set SystemProfile = Nothing

End Sub