将自定义操作添加到扩展中的“操作”下拉列表

Eri*_*cP. 1 acumatica

我正在尝试将我的自定义操作之一添加到 SOOrder 页面中现有的操作下拉列表中。我的代码定义如下:

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
    public PXAction<PX.Objects.SO.SOOrder> customAction;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Custom Action Title")]
    protected void CustomAction()
    {
        //stuff
    }

    public SOOrderEntry_Extension()
    {
       Base.action.AddMenuAction(customAction);
    }
}
Run Code Online (Sandbox Code Playgroud)

这样做会给我一个空对象引用错误。我接下来尝试定义我自己的动作列表如下:

public PXAction<PX.Objects.SO.SOOrder> ActionsMenu;
[PXButton]
[PXUIField(DisplayName = "Actions")]
protected virtual void actionsMenu()
{
}
Run Code Online (Sandbox Code Playgroud)

我也尝试使用

this.ActionsMenu.AddMenuAction(customAction) 
Run Code Online (Sandbox Code Playgroud)

但我再次得到了相同的空引用。我还尝试了以下代码:

public SOOrderEntry_Extension()
{
   Base.action.MenuAutoOpen = true;
}
Run Code Online (Sandbox Code Playgroud)

只是为了看看会发生什么并且也得到了相同的空引用错误:

[NullReferenceException:未将对象引用设置为对象的实例。]

编辑:Stackoverflow 不允许我在块引用中包含以下部分,因为它类似于代码。如果有人可以解决这个问题,那就去吧。

   PX.Data.PXGraph.CreateInstance(Type graphType, String prefix) +529
   PX.Web.UI.PXBaseDataSource.InstantiateDataGraph(Type type) +20
   PX.Web.UI.PXBaseDataSource.f(Type A_0) +400
   PX.Web.UI.PXBaseDataSource.g(Type A_0) +146
   PX.Web.UI.PXBaseDataSource.get_DataGraph() +302
   PX.Web.UI.PXBaseDataSource.k() +188
   PX.Web.UI.PXBaseDataSource.GetCommands() +69
   PX.Web.UI.PXBaseDataSource.GetCommandStates() +74
   PX.Web.UI.PXGrid.p() +132
   PX.Web.UI.PXGrid.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +476
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +149
   PX.Web.UI.PXGrid.CreateChildControls() +85
   System.Web.UI.Control.EnsureChildControls() +92
   System.Web.UI.WebControls.CompositeDataBoundControl.get_Controls() +16
   PX.Web.UI.PXSmartPanel.a(ControlCollection A_0, Boolean A_1, Boolean A_2) +257
   PX.Web.UI.PXSmartPanel.a(Boolean A_0) +98
   PX.Web.UI.PXSmartPanel.SetBindingState(Boolean load) +101
   PX.Web.UI.PXSmartPanel.OnInit(EventArgs e) +64
   System.Web.UI.Control.InitRecursive(Control namingContainer) +139
   System.Web.UI.Control.InitRecursive(Control namingContainer) +312
   System.Web.UI.Control.InitRecursive(Control namingContainer) +312
   System.Web.UI.Control.InitRecursive(Control namingContainer) +312
   System.Web.UI.Control.InitRecursive(Control namingContainer) +312
   System.Web.UI.Control.InitRecursive(Control namingContainer) +312
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +408
Run Code Online (Sandbox Code Playgroud)

在这一点上,我不确定我必须做什么才能将此自定义操作添加到下拉列表中,但我已经关注 Stack Overflow 上有关此问题的其他帖子,但找不到解决方案。我还查看了 T200,但无法找到有关如何执行此任务的任何直接建议。

Bre*_*dan 5

您应该将用于在基本操作菜单中添加自定义操作的代码放在对 Initialize 的覆盖中。在您的图形扩展中尝试此操作并删除您拥有的构造函数调用。

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
    public PXAction<PX.Objects.SO.SOOrder> customAction;

    [PXButton]
    [PXUIField(DisplayName = "Custom Action Title")]
    protected void CustomAction()
    {
        //stuff
    }

    public override void Initialize()
    {
        base.Initialize();
        Base.action.AddMenuAction(this.customAction);
    }
}
Run Code Online (Sandbox Code Playgroud)