web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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
    301,130 Super User 2025 Season 2 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
    237,967 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans