Hi all,
I want to attach a report pdf to files section of an invoice. I tried the below code snippet. It works for a single invoice only. But when we process multiple invoices from Process Invoices screen, file is attaching only for first invoice. For other invoices, file is not attaching.
Any idea about fixing this?
public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
foreach(ARInvoice invoice in adapter.Get<ARInvoice>())
{
//Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters["ARInvoice.DocType"] = invoice.DocType;
parameters["ARInvoice.RefNbr"] = invoice.RefNbr;
PXReportSettings settings = new PXReportSettings("AR641000");
//Report Processing
PX.Reports.Controls.Report report =
ReportLoader.CheckIfNull(nameof(ReportLoader)).LoadReport("AR641000", null);
ReportLoader.InitReportParameters(report, parameters, settings, false);
PX.Reports.Data.ReportNode reportNode =
ReportDataBinder.CheckIfNull(nameof(ReportDataBinder)).ProcessReportDataBinding(report);
//Generation PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode,
RenderType.FilterPdf).First();
PX.SM.FileInfo file = new PX.SM.FileInfo(reportNode.ExportFileName + "- "+invoice.RefNbr+ ".pdf", null, data);
var uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
uploadFileMaintenance.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Caches[typeof(ARInvoice)], invoice, file);
}
return baseMethod(adapter);
}