Home > Dynamics Ax > Adding Submenu and MenuItems to Ax-Menus using X++ code

Adding Submenu and MenuItems to Ax-Menus using X++ code


In this example I am going to illustrate how we can add the Menu items to the Menu’s using X++ code.

For this example, I am using form called InventParameters.

For this form I am creating new Display Menu Item, and the same menu item I am going to place in Invent menu.

Inventory Management à Setup à My Menus à My Invent Parameters

The above marked Submenu and Menu item are added to Invent Menu by using following X++ job.

static void AddSubmenuNItemstoMenu(Args _args)
{
    #AOT
    TreeNode        treeMenuItem;
    TreeNode        treeDisplayMenu;
    TreeNode        treeMenus;
    Menu            treeMenu, treeMenu1, treeMenu2;
    str             MenuName = "MyInventParameters";
    MenuFunction    menuFunction;

;
    treeMenuItem        =   TreeNode::findNode(#MenuItemsDisplayPath);
    treeDisplayMenu     =   TreeNode::findNode(#MenuItemsDisplayPath + "\" + MenuName);
    treeMenus           =   TreeNode::findNode(#MenusPath);

    if(!treeDisplayMenu)
    {
        treeMenuItem.AOTadd(MenuName);
        treeDisplayMenu = treeMenuItem.AOTfindChild(MenuName);
        treeDisplayMenu.AOTsetProperties("PROPERTIESn Object  #" + "InventParameters" + "n  Label  #" + "My Invent Parameters" + "n ENDPROPERTIESn");
        treeDisplayMenu.AOTsave();

        treeMenu = treeMenus.AOTfindChild("Invent");
        treeMenu1 = treeMenu.AOTfindChild("Setup");
        //treeMenu2 =  treeMenu1.AOTfindChild("Parameters");

        menuFunction = new MenuFunction(MenuName, MenuItemType::Display);

        treeMenu1.addSeparator();
        treeMenu1.addSubmenu("My Menus");
        treeMenu2 = treeMenu1.AOTfindChild("My Menus");
        treeMenu2.addMenuitem(menuFunction);

        treeMenu.AOTsave();

        print "New Menuitem is created under Invent menu";
        pause;
     }

}

In the above example I had used Menu class, instead of Treenode class for adding the Submenu and Menu items to the Menus of Ax.

After the above job is executed, you can find a new Display Menu Item at the following path

AOT à Menu Items à Display à MyInventParameters.

We can observe new Sub menu and Menu Item under Invent Menu also. 

AOTà Menusà Inventà Setupà My Menusà My Invent Parameters.

Smile…… Don't tell anyone smile

Advertisements
Categories: Dynamics Ax
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: