Get the full menu path of a given menu item in AX 2012

 

Purpose:

This post describes how we can get the full menu path of a given menu item.

Product:

Dynamics AX 2012

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
static void MAKMenuItemPath(Args _args)
{
    #TreeNodeSysNodeType
    #Properties
    #AOT
 
    TreeNode menuItemNode = TreeNode::findNode(@"\Menu Items\Display\HRMParameters");
    TreeNode menuNode;
    xRefPaths xRefPaths;
    xRefReferences xRefReferences;
    TreeNode parentNode;
    str path;
    xRefPaths = xRefPaths::find(menuItemNode.treeNodePath());
 
    while select xRefReferences
        where xRefReferences.referencePathRecId == xRefPaths.RecId
            && xRefReferences.Reference == XRefReference::Read
    {
        path = SysLabel::labelId2String(menuItemNode.AOTgetProperty(#PropertyLabel));
        menuNode = TreeNode::findNode(xRefPaths::findRecId(xRefReferences.xRefPathRecId).Path);
 
        if(menuNode && SysTreeNode::path2ApplObjectType(menuNode.treeNodePath()) == UtilElementType::Menu)
        {
            parentNode = menuNode.AOTparent();
 
            while(parentNode && parentNode.treeNodePath() != #MenusPath)
            {
                path = SysLabel::labelId2String(parentNode.AOTgetProperty(#PropertyLabel))  + " > " + path;
                parentNode = parentNode.AOTparent();
            }
 
            info(path);
        }
    }
}

Comments