I have code that list all main menus , then I create function to list all the menu items for every main menu:
public static void main(Args _args) { SysDictMenu _menu; str formName; str menuItemName; boolean iterateMenus(SysDictMenu _cmenu) { SysMenuEnumerator menuEnum = _cmenu.getEnumerator(); SysDictMenu subMenu; SysDictMenu parentSubMenu; boolean found; while (menuEnum.moveNext()) { subMenu = menuEnum.current(); if (subMenu.isMenu() || subMenu.isMenuReference()) { //info ("Menu "+subMenu.object().treeNodePath()); setPrefix(subMenu.label()); found = iterateMenus(subMenu); if (found) { return found; } } else if ((subMenu.isMenuItem()&& subMenu.menuItem().type() == MenuItemType::Display && subMenu.isVisible()) || (subMenu.isMenuItem()&& subMenu.menuItem().type() == MenuItemType::Action && subMenu.isVisible()) || (subMenu.isMenuItem()&& subMenu.menuItem().type() == MenuItemType::Output && subMenu.isVisible())) { info(subMenu.label()); } } return false; } AxMenu mainMenu = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetMenu(menuStr(MainMenu)); var enumerator = mainMenu.Elements.GetEnumerator(); while (enumerator.MoveNext()) { AxMenuElementMenuReference menuRef = enumerator.Current; TreeNode menuItemNode = TreeNode::findNode(menuRef.Name); _menu = SysDictMenu::newTreeNode(menuItemNode); iterateMenus(_menu); } }
An exception of type 'System.NullReferenceException' occurred in Dynamics.AX.SecurityTools.Class.FindMenuItem.netmodule but was not handled in user code
Additional information: Object reference not set to an instance of an object: in this Line :
SysMenuEnumerator menuEnum = _cmenu.getEnumerator();
it's a confusion with another account, now I was able to use my original account.
ok, I will continue discussing in that thread.
thanks :)
It's a different exception so maybe you should post a new question.
But seems you are trying to cast an object of type menu item into a variable of type menu reference.
I'm quite sure I remember you already discussing that issue in another thread. Please continue discussing that problem in that thread.
But it seems you have changed your username from Basma to Basma WED, so I can't find that old question for you from your profile.
Why did you create another username?
Please mark the helpful anwer(s) as verified if your question (in the title of this thread) is now resolved.
thanks Nikolaos,
but I get another exception:
Unable to cast object of type 'Microsoft.Dynamics.AX.Metadata.MetaModel.AxMenuElementMenuItem' to type 'Microsoft.Dynamics.AX.Metadata.MetaModel.AxMenuElementMenuReference' in this line :
while (enumerator.MoveNext()) { AxMenuElementMenuReference menuRef = enumerator.Current; TreeNode menuItemNode = TreeNode::findNode(menuRef.Name); _menu = SysDictMenu::newTreeNode(menuItemNode); if(_menu) iterateMenus(_menu); }
You need to check that _cMenu is not null before calling it's getEnumerator method.
Or check that "_menu" is not null before calling your iterateMenus method with the _menu parameter.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,297 Most Valuable Professional
nmaenpaa 101,156