This is possible using PXReportTools
and PX.SM.FileInfo
in your custom action. As Dmitrii Naumov pointed out in the comments, the method posted by Joshua Van Hoesen does this, you just need to set the report you need and set the parameters it expects.
Here is the required code for anyone that finds this question:
public class ARInvoiceEntryExtension : PXGraphExtension<ARInvoiceEntry>
{
public PXAction<ARInvoice> attachReport;
[PXUIField(DisplayName = "Attach Report")]
[PXButton]
public virtual IEnumerable AttachReport(PXAdapter adapter)
{
//Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters["ARInvoice.DocType"] = Base.Document.Current.DocType;
parameters["ARInvoice.RefNbr"] = Base.Document.Current.RefNbr;
//Report Processing
PX.Reports.Controls.Report _report = PXReportTools.LoadReport("AR641000", null);
PXReportTools.InitReportParameters(_report, parameters,
SettingsProvider.Instance.Default);
ReportNode reportNode = ReportProcessor.ProcessReport(_report);
//Generation PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode,
ReportProcessor.FilterPdf).First();
PX.SM.FileInfo file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, data);
UploadFileMaintenance graph = new UploadFileMaintenance();
graph.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);
return adapter.Get();
}
}