varReportName = "Title of Report Here"
varReportTemplate = "D:\Production\Crystal Reports\EBO\Client Reports\%varReportName%.rpt"
varReportOutput = "D:\Production\Crystal Reports\EBO\Exported Reports\%varReportName%.pdf"
varServer1Name = "Database Name here as specified in your data sources"
varServer1Database = ""
varServer1UserID = ""
varServer1Password = ""
varDestinationType = 1 ;Output to Disk
;varExportType = 1 ;Crystal Report
;varExportType = 2 ;Data Interchange
;varExportType = 3 ;Record Style
;varExportType = 5 ;Comma Seperated Values
;varExportType = 6 ;Tab Seperated Values
;varExportType = 7 ;Character Seperated Values
;varExportType = 8 ;Text
;varExportType = 9 ;Tab Seperated Text
;varExportType = 10 ;Paginated Text
;varExportType = 11 ;Lotus 123WKS
;varExportType = 12 ;Lotus 123WK1
;varExportType = 13 ;Lotus123WK3
;varExportType = 14 ;Word for Windows
;varExportType = 21 ;Excel 5.0
;varExportType = 22 ;Excel 5.0 Tabular
;varExportType = 23 ;ODBC
;varExportType = 24 ;HTML32 Standard
;varExportType = 25 ;Explorer32 Extend
;varExportType = 27 ;Excel 7.0
;varExportType = 28 ;Excel 7.0 Tabular
;varExportType = 29 ;Excel 8.0
;varExportType = 30 ;Excel 8.0 Tabular
varExportType = 31 ;Portable Document Format (PDF)
;varExportType = 32 ;HTML40
;varExportType = 33 ;Crystal Report 7.0
;varExportType = 34 ;Report Definition
;varExportType = 35 ;Exact Rich Text
;varExportType = 36 ;XML
varMailServerAddress = ""
varMailServerPort = ""
varMailServerUsername = ""
varMailServerPassword = ""
now=TimeYmdHms()
year = ItemExtract(1,now,":") mod 100
month = ItemExtract(2,now,":")
day = ItemExtract(3,now,":")
;Some days and months may only have one digit.
;To make sure they have two digits:
If StrLen(year) == 1 then year ="0%year%"
If StrLen(month) == 1 then month="0%month%"
If StrLen(day) == 1 then day= "0%day%"
varMessageFrom = ""
varMessageTo = ""
varMessageCC = ""
varMessageBCC = ""
varMessageSubject = "%varReportName% - %month%/%day%/%year%"
varMessageBody = StrCat("Hello All,",@LF,"Attached is the %varReportName% report.", @LF, @LF,"Thank you,",@LF,"Information Services")
varMessageFlags = ""
objCrystalApplication = objectopen("CrystalRuntime.Application")
objCrystalApplication.LogOnServer("PDSODBC.DLL",varServer1Name,varServer1Database,varServer1UserID,varServer1Password)
; open the saved report
objCrystalReport = objCrystalApplication.OpenReport(varReportTemplate)
objCrystalReport.DiscardSavedData()
;Export Report
objCrystalExport = objCrystalReport.ExportOptions
objCrystalExport.DestinationType = varDestinationType
objCrystalExport.FormatType = varExportType
objCrystalExport.DiskFileName = varReportOutput
Result = objCrystalReport.Export(BOOL:@false)
If Result == 0
;E-mail the file - success
Terminate(!AddExtender("WWPST44I.DLL"),"Title Here","Error Message Here")
kInit(varMailServerAddress,varMessageFrom,varMailServerUsername,varMailServerPassword,varMailServerPort)
kDest(varMessageTo,varMessageCC,varMessageBCC)
RC = kSendText(varMessageSubject,varMessageBody,varReportOutput,varMessageFlags)
If RC == 0 Then Message("EMAIL Processing","E-EMAIL send failed")
Else
;Export not succesful, log or e-mail error details.
End If
objectclose(objCrystalExport)
objectclose(objCrystalReport)
objectclose(objCrystalApplication)
Please note, if you have more than 1 database/source you will need to add the additional parameters as noted below where X is the current # of the data source (I.E. 2 - whatever). Just insert them below the other values in the code above:
varServerXDatabase = ""
varServerXUserID = ""
varServerXPassword = ""
objCrystalApplication.LogOnServer("PDSODBC.DLL",varServerXName,varServerXDatabase,varServerXUserID,varServerXPassword)