Skip to main content

Good day, 

In a customisation package I have to buttons on the Invoices & Memos (AR301000) screen - these buttons generate a report and attaches it as a file to the invoice or memo. 

This is the code to generate a PDF which works perfectly. 


#region Action Button - Export PDF Report
public PXAction<ARInvoice> ExportReport;
rPXButton(CommitChanges = true)]
rPXUIField(DisplayName = "Export PDF Report", Enabled = true)]
protected void exportReport()
{

// Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameterst"ARInvoice.DocType"] = Base.Document.Current.DocType;
parameterst"ARInvoice.RefNbr"] = Base.Document.Current.RefNbr;
var filename = Base.Document.Current.DocType + "_" + Base.Document.Current.RefNbr;

// Report Processing
Report _report = ReportLoader.LoadReport("AR641000", null);
ReportLoader.InitDefaultReportParameters(_report, parameters);

// Read Report
byteb] data = null;
using (StreamManager streamMgr = new StreamManager())
{
ReportRenderer.Render(RenderType.FilterPdf, _report, null, streamMgr);
data = streamMgr.MainStream.GetBytes();
}

//Generation PDF
PX.SM.FileInfo file = new PX.SM.FileInfo(filename + ".pdf", null, data);

//Saving report to Invoice as Attachment
UploadFileMaintenance graph = new UploadFileMaintenance();
graph.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);


}
#endregion

Here is the code that generates the Excel version


#region Action Button - Export Excel Report
public PXAction<ARInvoice> ExportReportExcel;
rPXButton(CommitChanges = true)]
rPXUIField(DisplayName = "Export Excel Report", Enabled = true)]
protected void exportReportExcel()
{
// Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameterst"ARInvoice.DocType"] = Base.Document.Current.DocType;
parameterst"ARInvoice.RefNbr"] = Base.Document.Current.RefNbr;
var filename = Base.Document.Current.DocType + "_" + Base.Document.Current.RefNbr;

// Report Processing
Report _report = ReportLoader.LoadReport("AR641000", null);
ReportLoader.InitDefaultReportParameters(_report, parameters);

// Read Report
byteb] data = null;
using (StreamManager streamMgr = new StreamManager())
{
ReportRenderer.Render(RenderType.FilterExcel, _report, null, streamMgr);
data = streamMgr.MainStream.GetBytes();
}

//Generation Excel
PX.SM.FileInfo file = new PX.SM.FileInfo(filename + ".xlsx", null, data);

//Saving report to Invoice as Attachment
UploadFileMaintenance graph = new UploadFileMaintenance();
graph.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);


}
#endregion

The excel version generates a report, but the data is either corrupt or cut off. 
When I run the report from the AR641000 screen, it works fine.

For example, the excel report generated from the report screen is 21kb while the one generated from the button is only 7kb. 

Has any one experienced this before or know of a bug? Any help is greatly appreciated. 

Thanks
 

It looks like a bug for me. I did some testing, and realized ReportRenderer only renders the first page of the report into the excel file.


@DewaldH @Zoltan Febert 

You need to provide deviceInfo parameter.

 

var deviceInfo = new System.Collections.Hashtable();

deviceInfonPX.Reports.Web.WebReport.Keys.PageNumber] = -1;
deviceInfonPX.Reports.Web.WebReport.Keys.StartPage] = -1;
deviceInfonPX.Reports.Web.WebReport.Keys.EndPage] = -1;

ReportRenderer.Render(format, reportNode, deviceInfo, manager);

 


Reply