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

Identifying Classes and Methods Subscribed to checkAddSubMenuDelegate

(0) ShareShare
ReportReport
Posted on by 105

Hi everyone,

In D365FO, the class SysMenuNavigationObjectFactory have the checkAddSubMenuDelegate delegate to extend and control menu item visibility based on feature management is enabled/disabled.

How can we identify all the classes that subscribe to or use the checkAddSubMenuDelegate delegate? Also, how can we determine the specific method names in those classes that are registered with this delegate?

For example, I would like to find a list like:

  • Class A → Method X → subscribed to checkAddSubMenuDelegate

  • Class B → Method Y → subscribed to checkAddSubMenuDelegate

  • Class C → Method Z → subscribed to checkAddSubMenuDelegate

What is the best way to find this information using X++ metadata APIs or Visual Studio in D365FO?

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

    The most efficient way is using cross-references ("Find references" action in Visual Studio).

     

    You could also scan code and look for [SubscribesTo(classstr(SysMenuNavigationObjectFactory), staticdelegatestr(SysMenuNavigationObjectFactory, checkAddSubMenuDelegate))] (while ignoring white spaces).

     

    Nevertheless I suspect you're solving a wrong problem.

  • BM-31070523-0 Profile Picture
    105 on at

    Hi @Martin Dráb thanks for your reply.

    One more thing I need to add is that I need to implement this logic in X++ code. The idea is to pass the menu item details to this method, identify the classes and methods that use the checkAddSubMenuDelegate, and then execute that logic to verify whether the menu item will be displayed in the UI or not.

    Is it possible to achieve this dynamically using X++ metadata APIs?

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

    Hi BM,

    I think Martin's right, and here's the key insight: you don't need to find and manually re-run the subscriber classes/methods at all  a delegate in X++ already does that aggregation for you automatically.

    When you call a delegate (like checkAddSubMenuDelegate), every subscribed method across the whole codebase runs automatically, in sequence, as part of that single call you're not supposed to enumerate subscribers and call their logic yourself; the delegate mechanism already does that internally. So trying to build your own registry of "Class A > Method X" and re-execute each one manually would actually bypass the very mechanism designed to solve this for you, and you'd risk missing subscribers or duplicating logic incorrectly.

    What you actually want to do instead: Just call the delegate itself, the same way SysMenuNavigationObjectFactory does internally:
    SysDictMenu rootMenu = ...; // your menu context SysDictMenu subMenu = SysDictMenu::newMenuName(menuItemDisplayStr(YourMenuItemName)); SysBoxedBoolean visibility = new SysBoxedBoolean(); visibility.value = true; SysMenuNavigationObjectFactory::checkAddSubMenuDelegate(rootMenu, subMenu, visibility); boolean isVisible = visibility.value;
    This single call automatically runs every class/method that's subscribed to checkAddSubMenuDelegateacross the entire application  Microsoft's standard ones and any custom ones your team added and the final visibility.value  reflects the combined result of all of them. You get exactly the answer you're after ("will this menu item be shown in the UI") without needing to discover or manually invoke any subscriber classes individually.

    So to directly answer your question  no, you don't need X++ metadata APIs to enumerate subscribers for this use case; calling the delegate itself already gives you the dynamic, combined result you're looking for.

  • BM-31070523-0 Profile Picture
    105 on at

    Thanks for your reply. Understood the suggestion what you have provided. According to my knowledge delegate method is not allowed call directly using class name like normal static method.

    Any other suggestions will be helpful!

     

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

    Delegates (both static and non-static) can be called, of course. They would be useless if we could register event handlers but we couldn't ever trigger the event. 

     

    This is how SysMenuNavigationObjectFactory.checkAddSubMenu() calls this particular delegate:

     

    SysMenuNavigationObjectFactory::checkAddSubMenuDelegate(rootMenu, subMenu, parameter);

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

    Hi Martin,

    Agree with you here, makes sense, delegates would be pointless if we could subscribe but never actually trigger them. Good confirmation that calling checkAddSubMenuDelegate directly is the right approach, exactly as SysMenuNavigationObjectFactory.checkAddSubMenu() does it internally

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

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 232 Most Valuable Professional

#3
Aayush Tiwari Profile Picture

Aayush Tiwari 222

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans