Make your menu items visible on main menu, conditionally,, using this cool feature of D365FO

 


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 = pamrTable.DXCCustomerSKUOnHold == NoYes::Yes;

                        break;

                }

            }

        }

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.

So much for today, see you soon again with another blog 💓💓💓 


Comments

Popular posts from this blog

X++ : mistakes which developers commit the most

Speed up your execution performance by using SysGlobalCaches