Skip to main content

Conditionally Hiding Menu Items in D365 FinOps Menus Without Using Feature Keys

In Microsoft Dynamics 365 Finance and Operations (D365 F&O), menu items are the links that can be clicked on to access forms, reports, classes, jobs, and queries. Feature keys are typically used to control the visibility of menu items based on user licenses. However, there are scenarios where you might want to hide menu items conditionally without relying on feature keys. 

This can be accomplished by extending the 'SysMenuNavigationObjectFactory' class and modifying the checkAddSubMenu(...) method. 

Suppose we want to hide the Vendor payment journal menu item under Accounts payable > Payments > Vendor payment journal

Steps

1. Create an extension of the SysMenuNavigationObjectFactory class

[ExtensionOf(classStr(SysMenuNavigationObjectFactory))]
internal final class SysMenuNavigationObjectFactory_PS_Extension
{

}

2. Create a Chain of Command (CoC) for the checkAddSubMenu method

[ExtensionOf(classStr(SysMenuNavigationObjectFactory))]
internal final class SysMenuNavigationObjectFactory_PS_Extension
{
    protected boolean checkAddSubMenu(SysDictMenu _rootMenu, SysDictMenu _subMenu)
    {
        boolean isVisible = next checkAddSubMenu(_rootMenu, _subMenu);

        isVisible = isVisible && this.checkMyConditionsForMenuItem(_subMenu.name());       

        return isVisible;
    }

}

3. Add your conditional logic to control the visibility of the menu item  

[ExtensionOf(classStr(SysMenuNavigationObjectFactory))]
internal final class SysMenuNavigationObjectFactory_PS_Extension
{

    protected boolean checkAddSubMenu(SysDictMenu _rootMenu, SysDictMenu _subMenu)
    {
        boolean isVisible = next checkAddSubMenu(_rootMenu, _subMenu);

        isVisible = isVisible && this.checkMyConditionsForMenuItem(_subMenu.name());    

        return isVisible;
    }

    private boolean checkMyConditionsForMenuItem(str _menuItem)
    {
        boolean isVisible = true;

        switch (_menuItem)
        {
            case menuItemDisplayStr(LedgerJournalTable5):
                // Add your logic to control the visibility here
                isVisible = false;
                break;
        }

        return isVisible;
    }
}

While feature keys are a powerful tool for controlling menu item visibility, there are situations where conditional hiding without relying on them is necessary. By leveraging  this X++ code, you can achieve flexible and dynamic menu item visibility in D365 F&O.

Comments

Popular posts from this blog

Electronic reporting (ER) - Create custom destinations

Electronic reporting (ER) is a configurable tool in Microsoft Dynamics 365 that helps create and maintain regulatory electronic reporting and payments. Configuration of reports can be done by business users with the use of Visual Editors without the need for developers. Refer to Electronic reporting (ER) overview - Finance & Operations | Dynamics 365 | Microsoft Docs for more information and detailed overview on ER. Destinations can be configured for each ER format configuration and its output component. Destinations can only be set up for ER configurations that have been imported into the current Finance instance, and for the formats that are available on the Electronic reporting configurations page. The functionality for ER destination management is available at Organization administration > Electronic reporting > Electronic reporting destination.  Microsoft Dynamics 365 for Operations version 1611 (November 2016) or later allows the use of  the following destinat...

Dynamics 365 eCommerce - Setting up the Development Environment

Microsoft Dynamics 365 Commerce is an evolution of Dynamics 365 Retail, which launched with new and improved capabilities for e-commerce, content management. To begin development and extension on Dynamics 365 eCommerce we'll need to install the following tools on the development machine: VSCODE - https://code.visualstudio.com Node.js - https://nodejs.org   (Currently version 10.x is the main supported version and the MSI installer can be found here : https://nodejs.org/dist/latest-v10.x/   ) Yarn - https://legacy.yarnpkg.com Git - https://git-scm.com/downloads (Note that development on eCommerce is only supported on Windows (as at 18/06/20).) Create a folder in your local drive to hold the e-Commerce site code - 'C:\repos' Open CMD in administrator mode and go to the folder directory you just created and clone the  Microsoft eCommerce repository with the following command:  git clone https://github.com/microsoft/Msdyn365.Commerce.Online.git This may take a while....