Adding Custom Action to “Actions” Drop Down in Extension

烂漫一生 提交于 2019-12-25 07:46:47

问题


I am trying to add one of my custom defined actions to the already existing Actions drop down in the SOOrder page. My code is defined as follows:

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

Doing this gives me a null object reference error. I next tried to define my own action list as follows:

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

I also tried using

this.ActionsMenu.AddMenuAction(customAction) 

but again I got the same null reference. I also attempted the following code:

public SOOrderEntry_Extension()
{
   Base.action.MenuAutoOpen = true;
}

just to see what would happen and also got the same null reference error:

[NullReferenceException: Object reference not set to an instance of an object.]

EDIT: Stackoverflow won't let me include the below portion in the blockquotes because it resembles code. If someone can fix this, go for it.

   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

At this point I'm not sure what I have to do to add this custom action into the drop down, but I've followed other posts on Stack Overflow regarding this issue and could not find a solution. I've also looked in T200 but wasn't able to find any direct advice on how to perform this task.


回答1:


You should put the code to add the custom action in the base action menu in an override to Initialize. Try this in your graph extension and remove the constructor call you have.

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


来源:https://stackoverflow.com/questions/42398301/adding-custom-action-to-actions-drop-down-in-extension

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