web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to Check Menu Item/Submenu Visibility Property at Runtime

(0) ShareShare
ReportReport
Posted on by 85

Hi Everyone,

In Dynamics 365 Finance & Operations, we can configure the Visibility property for menu items and submenus in the AOT.

Is there a way to check or retrieve the Visibility property of a menu item or submenu using X++ code at runtime?

For example, I would like to determine whether a particular menu item or submenu is configured as visible/hidden in the AOT and use that information in my X++ logic.

Could someone please provide guidance or an example of how to achieve this in X++?

Categories:
  • Martin Dráb Profile Picture
    241,313 Most Valuable Professional on at

    Can you tell me how you can configure the Visibility property of a menu item? As far as I know, there is no such a property.

  • CU-1234529-002 Profile Picture
    527 on at

    Hi, Agree with Martin menu items in the AOT don't have a "Visibility" property as such. What likely gets confused with this is Enabled (which controls access/greying out, often tied to security) or runtime visibility controlled by security role privileges, not a static AOT property.

    Could you clarify what you're actually trying to check is it whether a menu item is accessible to the current user's security role, or something else? That'll help point you to the right API (e.g., checking access via SecurityRight/xUserInfo type checks at runtime).

  • BM-31070523-0 Profile Picture
    85 on at

    Hi @Martin Dráb @CU-1234529-002 Please refer to the screenshot below for the Visible property I’m referring to. The property can be set to Yes or No (By default No).

  • Suggested answer
    CU-1234529-002 Profile Picture
    527 on at

    Hi @BM-31070523-0 ,

    Yes use SysDictMenu.isVisible() to retrieve the Visible property at runtime:

    SysDictMenu sysDictMenu = SysDictMenu::newMenuName(menuItemDisplayStr(YourMenuItemName)); boolean isVisible = sysDictMenu.isVisible();

    This is confirmed directly from the standard framework class SysMenuNavigationObjectFactory, which uses this same call to decide whether to render a menu item.

    Note: this only reads the static, design-time property  there's no setter via X++. If you need to dynamically control visibility at runtime (hide/show based on a condition), use this supported pattern instead:

    [SubscribesTo(classStr(SysMenuNavigationObjectFactory), staticDelegateStr(SysMenuNavigationObjectFactory, checkAddSubMenuDelegate))] 
    public static void menuItemVisibilityHandler(SysDictMenu _rootMenu, SysDictMenu _subMenu, SysBoxedBoolean _subMenuVisibility) 
    { 
    if (_subMenu.isMenuItem()) 
        { 
        var metaElement = _subMenu.GetMenuItemMetaElement(); 
        if (metaElement != null && metaElement.Name == menuItemDisplayStr(YourMenuItemName))     
        { _subMenuVisibility.value = false; // or your condition }
     } 
    }

    This doesn't change the stored AOT property, but it excludes the item from the navigation tree at runtime based on your logic  the effective equivalent of dynamic visibility control.
    Thanks, If this answer you question mark this as verified

  • Suggested answer
    Martin Dráb Profile Picture
    241,313 Most Valuable Professional on at

    Aha, so you don't actually mean the menu item, but a reference to a menu item from a menu.

     

    In that case, you can get that from MenuItemReferenceNode.IsVisible() method. To iterate elements in a menu, you can use SysMenuEnumerator object, which you'll get by calling SysDictMenu.getEnumerator().

     

    The solution suggested above is wrong, because SysDictMenu::newMenuName() accepts the name of a menu, not a menu item. And in general, the whole idea that a menu item name is sufficient to identify an entry in a menu is wrong. A menu item can be used in several menus and also there may be multiple menu items of the same name (but different types).

     

    You could use code like this to iterate menu item references in a menu and show their visibility:

     

    public static void main(Args _args)
    {
       new Demo().traverse(SysDictMenu::newMenuName('AccountsReceivable'));
    }

    void traverse(SysDictMenu _dictMenu)
    {
       SysMenuEnumerator enumerator = _dictMenu.getEnumerator();

       if (enumerator)
       {
           while (enumerator.moveNext())
           {
               SysDictMenu child = enumerator.current();
               str name = child.name();

               if (child.isMenuItem())
               {
                   info(strFmt("%1: %2",  child.menuItem().name(), child.isVisible()));
               }
               else
               {
                   this.traverse(child); // Recursion
               }
           }
       }

     

     

  • André Arnaud de Calavon Profile Picture
    307,684 Super User 2026 Season 2 on at

    Hi,

    You had a related question in the past. See: Solved: Identifying UI-visible menu items for a specific user

    Note that the loop shared by Martin is not considering the permissions for the user executing the code.

  • BM-31070523-0 Profile Picture
    85 on at

    Hi @CU-1234529-002 @Martin Dráb thanks for your information.

    Please correct me if I’m wrong. As I understand, isVisible() will only work based on the logged-in user's menu item access. 
    The isVisible() method does not only check whether the Visible property is set to Yes or No. It also determines whether the menu item should be displayed in the UI based on the currently logged-in user by checking all other conditions for e.g user has access or not for the menu item.

    But what if I need to check the Visible property for all menu items in the AOT, regardless of the user's access?

  • BM-31070523-0 Profile Picture
    85 on at

    Hi @André Arnaud de Cal… thank you for checking.

  • Suggested answer
    CU-1234529-002 Profile Picture
    527 on at

    Hi, Good question  based on the framework source 
    SysMenuNavigationObjectFactory.hasAccess()
    if(_current.rights() != AccessType::NoAccess && _current.isVisible())
    rights() and isVisible() are checked as two separate conditions. If  isVisible() already included user access, this would be redundant. So isVisible() should just reflect the static Visible property  not the user's security access.

    To be fully certain for your version, step through isVisible() in the debugger to confirm it has no internal security check.
    Thanks

  • Martin Dráb Profile Picture
    241,313 Most Valuable Professional on at

    @BM-31070523-0 Your understanding is incorrect. The solution I gave you addresses the Visible property only, not security and other things that we discussed in your previous threads.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 507 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 419 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 155

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans