Reputation: 233
I have the following code in a 2020 R1 system that I am trying to upgrade to 21.208. The problem is that the "SettingsProvider" does not have an "Instance" property so, this is causing a build error. Also, I'm getting warnings that the PXReportTools is obsolete but, I'm not sure what to replace it with?
This code is to get the byte[] of a report and then attach it to an email. What is the newer 21.208 way to do this?
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary["ARInvoice.DocType"] = current.DocType;
dictionary["ARInvoice.RefNbr"] = current.RefNbr;
Report report = PXReportTools.LoadReport("AR641000", (IPXResultset)null);
PXReportTools.InitReportParameters(report, (IDictionary<string, string>)dictionary, SettingsProvider.Instance.Default);
byte[] data = PX.Reports.Mail.Message.GenerateReport((object)ReportProcessor.ProcessReport(report), "PDF").First<byte[]>();
TIA!
Upvotes: 0
Views: 367
Reputation: 907
As of 21R2 for report loading you need to import two dependencies in your graph using dependency injection
[InjectDependency]
protected IReportLoaderService ReportLoader { get; private set; }
[InjectDependency]
protected IReportRenderer ReportRenderer { get; private set; }
Then using this two services you can retrieve the byte report data using the following:
Dictionary<String, String> parameters = new Dictionary<String, String>();
Report _report = reportLoader.LoadReport(ARReports.InvoiceMemoReportID, null);
reportLoader.InitDefaultReportParameters(_report, parameters);
byte[] fileDate = null;
using (StreamManager streamMgr = new StreamManager())
{
reportRenderer.Render(RenderType.FilterPdf, _report, deviceInfo: null, streamMgr);
fileData = streamMgr.MainStream.GetBytes();
}
You can also save it in a FileInfo Object if you want to save it locally with a name.
Upvotes: 2