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

  • Verified answer
    reachnaidu Profile Picture
    890 on at
    RE: Syntax for Menu Items (display/output/action) in X++

    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..

  • Community Member Profile Picture
    on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

    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.

  • Martin Dráb Profile Picture
    231,723 Most Valuable Professional on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

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

  • Ehtasham Rahman Profile Picture
    672 on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

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

       }

    }

  • Suggested answer
    reachnaidu Profile Picture
    890 on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

    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.

  • reachnaidu Profile Picture
    890 on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

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

    }

  • Community Member Profile Picture
    on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

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

  • Ehtasham Rahman Profile Picture
    672 on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

    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
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

    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.

  • André Arnaud de Calavon Profile Picture
    292,850 Super User 2025 Season 1 on at
    RE: Syntax for Menu Items (display/output/action) in X++ (AX2012)

    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?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,850 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans