Question
· Oct 13, 2019

Generate ZEN report, PDF file programmatically

Hi All,

I have a ZEN report, which gives a PDF output, i want to generate this report programmatically, save to a location in the disk. Here is my method so far

 ClassMethod GenerateReport(ReportID, ReportClass, P1, P2, P3, P4, P5, P6, P7, P8, P9, PUser, PUserID, PUserProfileID, mode = 2, ByRef outputfile = "") As %Status
{
set filename=""
set ZenClassName=$piece(ReportClass,".cls")
set oRpt=$classmethod(ZenClassName,"%New") 
set oRpt.RUID=##class(websys.Report).GetRUID(P1,P2,P3,P4,P5,P6,P7,P8,P9,PUser,PUserID,"",PUserProfileID)
set FileExt=..GetModeExt(mode)
if outputfile=""
{
set filepath=..getTempPath() set pdffile=ZenClassName_"_"_$zstrip($piece(##class(Ens.Util.File).CreateTimestamp(),"_",3),"*P")_"_"_$random(9999)_"."_FileExt
set filename=filepath_pdffile
}
else
{
set filename=outputfile
} if (FileExt="PDF"){ set renderserver=""
if $get(^%SYS("zenreport","renderserverport"))'="" {
set renderserver=##class(websys.Report).RenderServerCheck()
}

if ReportID {
set ZenSplitMerge=0
set (ZenSplitMergeElement, ZenSplitMergeElementCount)=""
&SQL(SELECT ZenSplitMerge, ZenSplitMergeElement, ZenSplitMergeElementCount INTO :ZenSplitMerge, :ZenSplitMergeElement, :ZenSplitMergeElementCount FROM websys.report WHERE ID= :ReportID)
if SQLCODE set ZenSplitMerge=0
if $get(ZenSplitMerge)=1,$get(ZenSplitMergeElement)="" set ZenSplitMerge=0
}
if $get(ZenSplitMerge)=1 {
set oRpt.SplitAndMerge=1
set oRpt.RepeatingElement=$get(ZenSplitMergeElement)
if $get(ZenSplitMergeElementCount)'="" set oRpt.CountRepeatingElement=$get(ZenSplitMergeElementCount)
}
//Generates pdf to file on DB server
if renderserver="" {
set tSC=oRpt.GenerateReport(filename,2)
else {
set tSC=oRpt.GenerateReport(filename,2,0,renderserver)
} }
else{
try { set tSC=oRpt.GenerateReport(filename,mode)  catch (err) {
set tSC = $$$ADDSC(sc,err.AsStatus())
}
} 
set outputfile=filename
quit tSC
}

This method generates a .xsl and .xml file which has my output, how can i get a pdf?

Thanks in Advance.

Rizmaan

Discussion (3)1
Log in or sign up to continue

thank you,

I am using the following method

set tSC=oRpt.GenerateReport(filename,2) 

which the filename is a .pdf file, and when i check the output folder a .xml, which has my output and a .xsl file

tSC returns this

 tSC="0 "_$lb($lb(5001,"Unable to create ReportDisplay object.",,,,,,,,$lb(,"TRAK",$lb("e^%DrawToXSLFO+7^%ZEN.Report.reportPage.1^1","e^%MakeToXSLFOFile+14^%ZEN.Report.reportPage.1^1","e^%DisplayPDF1+6^%ZEN.Report.reportPage.1^1","e^%DisplayPDF+7^%ZEN.Report.reportPage.1^1","e^zCallReport+33^%ZEN.Report.reportPage.1^1","e^zGenerateReport+4^%ZEN.Report.reportPage.1^1","e^zGenerateReport+38^Region.MEXX.Report.RQM.App.Utils.1^1","e^zRepotToCSV+27^Region.MEXX.Report.RQM.App.Utils.1^1","d^zProcessNextReport+27^Region.MEXX.Report.RQM.App.Utils.1^1","d^zDebugStub+30^%Debugger.System.1^2","d^^^0"))))/* ERROR #5001: Unable to create ReportDisplay object. */

any idea why