Tuesday, October 7, 2014

Create Menuitem at runtime or through X++ and set properties

Hi Guys,

Here is the example of creating menuitem through X++ code.


static void CreatingMenuItemRutime(Args _args)
{
    
    TreeNode          treeMenuItem;
    str                    menuName = "TestOutputMenuItem";
    str                    properties;
    #AOT
    #Properties
    ;
    
    treeMenuItem = TreeNode::findNode(#MenuItemsOutputPath);
    treeMenuItem.AOTadd(menuName);
    
    treeMenuItem = treeMenuItem.AOTfindChild(menuName);
    properties = treeMenuItem.AOTgetProperties();
    
    properties = setProperty( properties, #PropertyLabel,'Sales Report');
    properties = setProperty( properties, #PropertyObjectType, 'Class');
    properties = setProperty( properties, #PropertyObject,'SalesFormLetter');
    properties = setProperty( properties, #PropertyParameters, 'ReportX1\\Report');
    
    treeMenuItem.AOTsetProperties(properties);
    
    treeMenuItem.AOTsave();
    print "New Menuitem is created under output menuitem";
    pause;
}