Scheduled Script to export a report to PDF file

Discussions relating to breakout scripting, .NET and COM programming with Jiwa objects.

Scheduled Script to export a report to PDF file

Postby Mike.Sheen » Thu Nov 06, 2008 10:10 am

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
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Return to Technical / Programming

Who is online

Users browsing this forum: No registered users and 8 guests