首先,创建一个报告模板并将其保存为PXReport.xml文件。确保该文件位于App_Data/Reports路径下。
接下来,在电子邮件发送事件中,读取报告模板并生成报告。
protected void SOInvoice_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
{
var doc = (ARInvoice)e.Row;
var reportID = "CUSTOM_REPORT";
var parameters = new Dictionary
{
["InvoiceID"] = doc.DocType,
["InvoiceType"] = doc.DocType
};
var reportNode = GetReportNode(reportID);
using (var report = PXReportTools.LoadReport(reportNode, null))
{
PXReportTools.InitReportParameters(report, parameters, PXSettingProvider.Instance.Default);
var result = PXReportTools.RenderReport(report, null, PXSettingProvider.Instance.Default);
var attachment = new PX.SM.FileInfo($"ARInvoice-{doc.RefNbr}.pdf", null, result.First);
attachment.Data = result.Second;
bool alwaysAttachReport = true; //set this to false if you only want to attach the report if certain conditions are met
if (alwaysAttachReport || /* insert condition here */)
{
PXNoteAttribute.SetFileNotes(SOInvoice.Cache, e.Row, new[] { attachment });
sender.Graph.MailSend.AddAttachment(attachment);
}
}
}
private XmlNode GetReportNode(string reportID)
{
var app = PX.Common.PXInstanceHelper.Current;
var resolver = (PX.Data.Processing.PXFileResolver)app.GetService(typeof(PX.Data.Processing.IPXFileResolver));
var node = PX.Data.PXReportsMaint.LoadReport(reportID, app, resolver);
return node;
}
sender.Graph.MailSend.AddAttachment(attachment);
注意:上述代码仅适用于添加单个报告至附件。如果需要添加多个报告,可以将attachment
变量复制到一个列表中并在电子邮件发送事件结束时循环遍历。
上一篇:Acumatica-GridinPXTabItemonPXSmartPanelNotAppearingonScreen
下一篇:Acumatica-OverrideConvertQuoteToProjecttoincludecustomfields