I am trying to attach a file one specific report to the shipment record when the shipment is confirmed. Can anyone here help me with the flow on how to do this with a customization.
Thanks
I am trying to attach a file one specific report to the shipment record when the shipment is confirmed. Can anyone here help me with the flow on how to do this with a customization.
Thanks
Best answer by vardan22
To be able to attach report in the any document you need to go through with following steps:
Below the complete example for the Shipments entry:
using PX.Data;
using PX.Objects.SO;
using PX.Reports;//from PX.Reports.dll
using PX.Reports.Controls;//from PX.Reports.dll
using PX.Reports.Data;//from PX.Reports.dll
using PX.SM;
using System.Collections.Generic;
using System.Linq;
namespace AttachReport
{
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
public static bool IsActive() => true;
#region InjectDependency
[InjectDependency]
protected IReportLoaderService ReportLoader { get; private set; }
[InjectDependency]
protected IReportDataBinder ReportDataBinder { get; private set; }
#endregion
#region Override
public delegate void ConfirmShipmentDelegate(SOOrderEntry docgraph, SOShipment shiporder);
[PXOverride]
public virtual void ConfirmShipment(SOOrderEntry docgraph, SOShipment shiporder, ConfirmShipmentDelegate shipmentDelegate)
{
shipmentDelegate(docgraph, shiporder);
const string reportID = "SO642000";
var parameters = new Dictionary<string, string> { };
parameters.Add(nameof(SOShipment) + "." + nameof(SOShipment.ShipmentNbr), shiporder.ShipmentNbr);
byte[] byteArray = GetPDFDocumentFromReport(parameters, reportID);
UploadFileMaintenance upl = PXGraph.CreateInstance<UploadFileMaintenance>();
FileInfo fileinfo = new FileInfo($"{shiporder.ShipmentNbr}.pdf", null, byteArray);
if (upl.SaveFile(fileinfo, FileExistsAction.CreateVersion))
{
PXNoteAttribute.SetFileNotes(this.Base.Document.Cache, this.Base.Document.Current, fileinfo.UID.Value);
this.Base.Save.Press();
}
}
#endregion
#region helper
public virtual byte[] GetPDFDocumentFromReport(Dictionary<string, string> parameters, string reportID)
{
Report _report = ReportLoader.LoadReport(reportID, null);
ReportLoader.InitReportParameters(_report, parameters, new PXReportSettings());
ReportNode reportNode = ReportDataBinder.ProcessReportDataBinding(_report);
//Generation PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode, RenderType.FilterPdf).First();
return data;
}
#endregion
}
}
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.