Hi All,
Show example for you today – how to remove action from menu based on example of ChangeID function in CustomerMaint graph.
Problem
If you take VendorMaint and try to find who ChangeID is declared there you will be able to find following code:
public PXAction<VendorR> action; [PXUIField(DisplayName = "Actions", MapEnableRights = PXCacheRights.Select)] [PXButton] protected virtual IEnumerable Action(PXAdapter adapter) { return adapter.Get(); } public PXChangeID<VendorR, VendorR.acctCD> ChangeID; public VendorMaint() { //... action.AddMenuAction(ChangeID); //... }
So you can see here that ChangeID button is added as a menu to the Action button. This works pretty well accordingly to example with adding sub-menu actions here.
Now the question – what if we need to remove or hide this action?
- We can’t use automation steps as they cannot make button invisible.
- We cannot use PXUIFieldAttribute on ChangeID as this button is already invisible and menu item is not in sнтс with button visibility.
- We cannot decoratively remove actions from graph.
Solution
The solution that I have found is to just remove the menu item from the list after it is added. As original code is in the graph constructor, we can’t really override it, we just can adjust it after. The best way for that is Initialize method on extension, that will be fired right after constructor.
public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint> { public override void Initialize() { base.Initialize(); //Remove ChangeID Menue RemoveChangeID(Base, Base.ChangeID, "Action"); } public static void RemoveChangeID(PXGraph graph, PXAction action, String name) { PXButtonState astate = action.GetState(null) as PXButtonState; if (astate != null) { PXButtonState bstate = graph.Actions[name].GetState(null) as PXButtonState; if (bstate != null && bstate.Menus != null) { ButtonMenu[] array = bstate.Menus.Where(b => b.Command != astate.Name).ToArray(); graph.Actions[name].SetMenu(array); } } } }
Now you can see that Menu item ChangeID has been removed from the screen.
Hope it helps!