Add a Report Menu item via code rather than Automa

2019-09-16 16:44发布

问题:

I am trying to add a report to the Reports menu of the SO Order Entry page via code rather than using Automation steps. The code I am using is as follows but is producing the errors: error CS0122: 'PX.Objects.SO.SOOrderEntry.Report(PX.Data.PXAdapter, string)' is inaccessible due to its protection level error CS0119: 'PX.Objects.SO.SOOrderEntry.Report(PX.Data.PXAdapter, string)' is a 'method', which is not valid in the given context

public SOOrderEntry_Extension()
 {
    Base.Report.AddMenuAction(sOAcknowledgementReport);
 }

public PXAction<SOOrder> sOAcknowledgementReport;
    [PXButton]
    [PXUIField(DisplayName = "SO Acknowledgement Report")]
    protected void SOAcknowledgementReport()
       {
          if (Base.Document.Current.OrderNbr != string.Empty)
        {
           throw newPXReportRequiredException(Base.Document.Current, "SO641010", string.Empty);
        }
      }

Does anybody have suggestions how to add a Report to the reports menu via code rather than using Automation Steps?

回答1:

I think you can override Initialize() method and add the Report to report menu there. See the snippet code below on SOOrderEntry Graph Extension:

public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
{


    public override void Initialize()
    {
        Base.report.AddMenuAction(sOAcknowledgementReport);
    }


    public PXAction<SOOrder> sOAcknowledgementReport;
    [PXButton]
    [PXUIField(DisplayName = "SO Acknowledgement Report")]
    protected void SOAcknowledgementReport()
    {
        if (Base.Document.Current.OrderNbr != string.Empty)
        {
           throw new PXException("Test");
        }
    }

}


回答2:

First you want to perform the menu add in the Initialize call and use "report" vs "Report".

public override void Initialize()
{
    base.Initialize();
    //Edit:  use report vs Report as HB_ACUMATICA mentioned
    Base.report.AddMenuAction(sOAcknowledgementReport);
}

Second, you will need to indicate the button as enabled by extending RowSelected. I think the automation stuff auto disables the button, so this is necessary to turn the button back using any condition you need to enable the button.

public virtual void SOOrder_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected del)
{
    del?.Invoke(sender, e);
    sOAcknowledgementReport.SetEnabled(true);
}


标签: acumatica