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();