Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Learn with Subs / Make your menu items visibl...

Make your menu items visible on main menu, conditionally, using this cool hack

Subhad365 Profile Picture Subhad365 17 User Group Leader


Wassup guys?

I am sure you must have encountered this situation where you needed to display your menuItems, on main menu, based on some condition, haven't you? This was only possible by using config keys and flights. Things get a bit tricky,  when suppose you have a requirement like this: you need to make it dynamic, by introducing a toggle switch on a field on a paremeter form. 

Suppose on Accounts Receivables Parameters >> You have a field called 'Show US customer'. You have a requirement that says when you turn on this toggle, then only the menuItem 'Input SSN details', under AR module.

This is now highly acheivable by leveraging subscription to 'SysMenuNavigationObjectFactory' class, simply by saying

a. Create a new class USMenuItemsVisibilityManager

b. Copy the following method, with proper documentation (don't change signature/anything else)

[SubscribesTo(classstr(SysMenuNavigationObjectFactory), staticdelegatestr(SysMenuNavigationObjectFactory, checkAddSubMenuDelegate)), Hookable(false)]

    internal static void menuItemVisibilityHandler(SysDictMenu _rootMenu, SysDictMenu _subMenu, SysBoxedBoolean _subMenuVisibility)

c. And then just introduce the following code in the method:

if (_subMenu.isMenuItem())

        {

            var metaElement = _subMenu.GetMenuItemMetaElement();

            if (metaElement != null)

            {

                vendParameters parmTable =  VendParameters::find();

                switch (metaElement.Name)

                {

                    case menuItemDisplayStr(SHOWSSNCustInputTable): //give the name of your menu item here                   

                        _subMenuVisibility.value = parmTable.DAXCustomerSKUOnHold == NoYes::Yes;

                        break;

                }

            }

        }

Here DAXCustomerSKUOnHold  is the field from Vendor parameters table, which when turned on/off, we need to make the Menu item for Customer SSN Details.

Change the name of the menu item here, as you need. When you save the code and get back to Vend parameters table, and change the toggle to No, and reload your application page, the menu item is gone!

Yes, this cool hack can help you manipulate the visibility of your application's menu items, as you need.


Comments

*This post is locked for comments