Solved

Pass Parameters to a report through code

  • 25 January 2023
  • 3 replies
  • 302 views

Userlevel 4
Badge +1

In 2021r2, the compiler complains about obsolete PXReportTools and ReportProcessor methods.  And also, "SettingsProvider" does not have an "Instance" property so, this is causing a build error. How can I fix this? Below is the code snippet currently I’m using.     

 

//Report Processing 

PX.Reports.Controls.Report _report = PXReportTools.LoadReport(“AP621C1”, 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();

icon

Best answer by ruchikasharma23 25 January 2023, 20:53

View original

3 replies

Userlevel 3
Badge

Hi Charithalakshan,
 

You are right, in 2021R2  the  PX.Data.Reports.PXReportTools is deprecated and you can use DI instead.

So something like that:
 

[InjectDependency]

protected PX.Reports.IReportLoaderService ReportLoader { get; private set; }

 

Reports.Controls.Report report = ReportLoader.LoadReport(reportID, ...);

Hope that helps

Userlevel 5
Badge +1

Hi @charithalakshan49 
In addition, you can find an example of a graph extension of SOOrderEntry which implements the new DI below:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.CA;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.DR;
using PX.Objects.EP;
using PX.Objects.GL;
using PX.Objects.IN;
using PX.Objects.PM;
using PX.Objects.PO;
using PX.Objects.TX;
using POLine = PX.Objects.PO.POLine;
using POOrder = PX.Objects.PO.POOrder;
using System.Threading.Tasks;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects.AR.CCPaymentProcessing;
using PX.Objects.AR.CCPaymentProcessing.Common;
using PX.Objects.AR.CCPaymentProcessing.Helpers;
using PX.Objects.AR.CCPaymentProcessing.Interfaces;
using ARRegisterAlias = PX.Objects.AR.Standalone.ARRegisterAlias;
using PX.Objects.AR.MigrationMode;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects.Common.Extensions;
using PX.Objects.IN.Overrides.INDocumentRelease;
using PX.CS.Contracts.Interfaces;
using PX.Data.DependencyInjection;
using PX.Data.WorkflowAPI;
using PX.Objects.Extensions.PaymentTransaction;
using PX.Objects.SO.GraphExtensions.CarrierRates;
using PX.Objects.SO.GraphExtensions.SOOrderEntryExt;
using PX.Objects.SO.Attributes;
using PX.Objects.Common.Attributes;
using PX.Objects.Common.Bql;
using OrderActions = PX.Objects.SO.SOOrderEntryActionsAttribute;
using PX.Objects.SO.DAC.Projections;
using PX.Data.BQL.Fluent;
using PX.Objects;
using PX.Objects.SO;
using PX.Data.Reports;
using PX.SM;
using PX.Reports.Controls;
using PX.Reports.Data;
using System.Configuration;
using PX.Reports;
using CommonServiceLocator;


namespace PX.Objects.SO
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
#region Event Handlers
[InjectDependency]
protected IReportLoaderService ReportLoader { get; private set; }

[InjectDependency]
protected internal PX.Reports.IReportDataBinder ReportDataBinder { get; private set; }

public PXAction<SOOrder> exportReport;
[PXUIField(DisplayName = "Export Report", Enabled =true)]
[PXButton]
public virtual IEnumerable ExportReport(PXAdapter adapter)
{
//Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters["SOOrder.OrderType"] = Base.Document.Current.OrderType;
parameters["SOOrder.OrderNbr"] = Base.Document.Current.OrderNbr;
PXReportSettings settings = new PXReportSettings("SO641010");

//Report Processing

PX.Reports.Controls.Report report = ReportLoader.CheckIfNull(nameof(ReportLoader)).LoadReport("SO641010", 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 + ".pdf", null, data);

var uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
uploadFileMaintenance.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);

return adapter.Get();

#endregion
}
#region Event Handler
protected virtual void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{

InvokeBaseHandler?.Invoke(cache, e);
exportReport.SetEnabled(true);
}
#endregion
}
}

 

Userlevel 4
Badge +1

@ruchikasharma23 @evgenyafanasiev56 It worked! Thanks for the responses!

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