Skip to main content
Solved

Pass Parameters to a report through code


Forum|alt.badge.img+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();

Best answer by ruchikasharma23

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

 

View original
Did this topic help you find an answer to your question?

4 replies

Evgeny Afanasiev
Acumatica Moderator
Forum|alt.badge.img

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


Forum|alt.badge.img+2
  • Acumatica Moderator
  • 56 replies
  • Answer
  • January 25, 2023

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

 


Forum|alt.badge.img+1

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


Forum|alt.badge.img
ruchikasharma23 wrote:

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

 

I got this error with 2024R1 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings