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 :
Microsoft Dynamics AX (Archived)

Syntax for Menu Items (display/output/action) in X++

(0) ShareShare
ReportReport
Posted on by

Hey all,

I am cycling through the Menu TreeNodes in AX, and I'm unsure how to identify display menu items through my loop.  In pseudocode, I am looking for:

if(TreeNode.AOTName() == <Display Menu Item>)

I am looking for what the Syntax would be to make that statement true for <Display Menu Item>.

Thank you

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,730 Super User 2026 Season 1 on at

    Please elaborate. What is the complete requirement? Are you looking for only menu items of type display or a certain menu item with a specific name?

  • Community Member Profile Picture
    on at

    I am cycling through the <Menus> object within the AOT TreeNode.  When you open the folders, you eventually hit Menu Items of various types.

    My code already goes through all the folder objects and hits the Menu Items.  I want to have a conditional for when I hit a Menu Item.  Essentially I would be looking for Menu Items of all types (not just display), but display seems to be the most common.

  • Ehtasham Rahman Profile Picture
    672 on at

    Can you please paste your piece of code here? It'll help to make me to give you solution.

  • Community Member Profile Picture
    on at

    You bet, here is the code.

    Class main:

    --------------------------------------------------------------------------------------

    public void main()
    {
    #AOT
    TreeNode tNode;
    TreeNodeIterator tIterator;
    TreeNode controlMenuItemNode;
    TreeNode controlNode;

    tNode = TreeNode::findNode(strFmt('%1', #MenusPath));

    tIterator = tNode.AOTiterator();
    controlNode = tIterator.next();

    while(controlNode != null)
    {

    //Display's all items
    info(ControlNode.AOTname());

    //What I want to display

    /*if(ControlNode.AOTname() == <Display Menu Item Syntax>)

    {

    //Insert Logic here

    }

    */
    this.iterateTreenode(TreeNode::findNode(strFmt('%1\\%2', #MenusPath, ControlNode.AOTname())));
    controlNode = tIterator.next();
    }

    info('Complete');
    }

    -------------------------------------------------------------------------------------

    Class method 1:

    -------------------------------------------------------------------------------------

    private void iterateTreenode(TreeNode tNode)
    {
    #AOT
    TreeNodeIterator tIterator;
    TreeNode controlMenuItemNode;
    TreeNode controlNode;

    tIterator = tNode.AOTiterator();
    controlNode = tIterator.next();

    while(controlNode != null)
    {
    info(ControlNode.AOTname());
    this.iterateTreenode(ControlNode);

    controlNode = tIterator.next();
    }
    }

    ---------------------------------------------------------------------------

    I then call my class through a job

    ---------------------------------------------------------------------------

    static void IterateMenusJob(Args _args)
    {
    IterateMenusClass im = new IterateMenusClass();
    im.main();
    }

  • reachnaidu Profile Picture
    890 on at

    Try this ..

    static void searchSubNodes(Args _args)

    {

       str         treeNodeNames;

       void searchSubNodes (TreeNode _treeNode)

       {

           if (!_treeNode)

               return;

           _treeNode = _treeNode.AOTfirstChild();

           while (_treeNode)

           {

               if (_treeNode.AOTfirstChild())

               {

                   searchSubNodes(_treeNode);

               }

               if (_treeNode.applObjectType())

               {

                   treeNodeNames += strfmt("%1\n", _treeNode.treeNodeName());

               }

               _treeNode = _treeNode.AOTnextSibling();

           }

       }

       ;

       searchSubNodes (TreeNode::findNode(@"\Menu Items"));

       info(treeNodeNames);

    }

  • Suggested answer
    reachnaidu Profile Picture
    890 on at

    A small modification to the above Job :

    static void searchSubNodes(Args _args)

    {

      str         treeNodeNames;

      void searchSubNodes (TreeNode _treeNode)

      {

          if (!_treeNode)

              return;

          _treeNode = _treeNode.AOTfirstChild();

          while (_treeNode)

          {

              if (_treeNode.AOTfirstChild())

              {

                  searchSubNodes(_treeNode);

              }

              if (_treeNode.applObjectType())

              {

                  treeNodeNames += strfmt("%1 %2\n", _treeNode.treeNodeName(),_treeNode.AOTgetProperty('ObjectType'));

              }

              _treeNode = _treeNode.AOTnextSibling();

          }

      }

      ;

      searchSubNodes (TreeNode::findNode(@"\Menu Items"));

      info(treeNodeNames);

    }

    Here we can find the Menu item Type by checking treeNode.AOTgetProperty('ObjectType') which gives either Form,Report or Class.. Based on that you can iterate through display, Output and Action menu items.

    Hope this solves your problem.

  • Ehtasham Rahman Profile Picture
    672 on at

    Try the following job:

    static void LoopInAOTByChoice(Args _args)

    {

       UtilElements    UtilElementsLocal;

       ;

       while select * from UtilElementsLocal

           where UtilElementsLocal.recordType == UtilElementType::DisplayTool  //Set what AOT node you want to loop in

           //&& UtilElementsLocal.utilLevel == global::currentAOLayer()          //Set this condition if you want to loop in current layer's element

       {

             info(UtilElementsLocal.name) ;

       }

    }

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You might be looking for if (controlNode.AOTname() == menuItemDisplayStr(YourMenuItem)).

  • Community Member Profile Picture
    on at

    It would be close this, but it I would need something logically equal to if(menuItemDisplayStr(controlNode.AOTName())) is valid to check to see if the AOTName() returned is a display menu item.  However, it does not work this way because menuItemDisplayStr is an intrinsic function.

  • Verified answer
    reachnaidu Profile Picture
    890 on at

    Did you check this ?

    treeNode.AOTgetProperty('ObjectType') which gives either Form,Report or Class.. Based on that we know Form belongs to DisplayMenuitem, Report to Output and Class to Action..

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans