Solved

Create a report and attach it to shipment record

  • 18 November 2023
  • 2 replies
  • 84 views

Userlevel 2
Badge

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

icon

Best answer by vardan22 20 November 2023, 08:52

View original

2 replies

Userlevel 5
Badge

Hi @param2022 , just want to confirm a few things….

  1. When the shipment is Confirmed, a report is attached to the shipment record in Acumatica. (not an additional report attachment on the shipment confirmation notification to customer).
  2. Does the attached report run off parameters needed from the provided shipment? 
Userlevel 4
Badge +1

To be able to attach report in the any document you need to go through with following steps:

  1. Get the .pdf file byte array for the particular report using the report Parameters and ScreenID
  2. Make sure the used parameters are listed in the Viewer Fields tab of the Schema Builder on the Acumatica Report Designer
  3. Save the byte array as file in the db using UploadFileMaintenance graph
  4. Set as attachment to the corresponding document using SetFileNotes method from PXNoteAttribute

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
}
}

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved