Add a Report Menu item via code rather than Automation Steps

倖福魔咒の 提交于 2019-12-11 15:21:59

问题


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


来源:https://stackoverflow.com/questions/45242981/add-a-report-menu-item-via-code-rather-than-automation-steps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!