Home > Ax Technical > Creating new Syscontext Menu in Dynamics Ax 4.0

Creating new Syscontext Menu in Dynamics Ax 4.0

                     
 Custom menu can be added to "Add-ins" portion of the context menu, this article would explain you in creating  a menu like that…
 
         
 
1. Drag the menuItem that you wanted to be activated in to the syscontextmenu
    \Menus\sysContextMenu
  
2. Create a sub menu if you want your add ins menu to appear under one submenu like Copy\EntierPath or Copy\Name…. or a separator if you want to differentiate that particular menu item.
 
                The moment you drag and drop your menuitem in to Syscontextmenu, the new context menu would start appearing in the context menu. The steps to follow would help you in finding out the objects that are selected and process it.
 
3. The next step would be to decide when the context menu should appear  when you select forms or tables,
   and can it work for multiple selection..
   To implement this you will have to go to
   \Classes\SysContextMenu\VerifyItem – Method
 
   You would find a big switch case statement like this …
   switch (menuItemType)
  {
        case MenuItemType::Display:
            switch (menuItemName)
            {               
                case menuitemdisplaystr(SysVisioAddIn):
                    …
                case menuitemdisplaystr(XRefReferencesUsedBy):
                    
                    …
                case menuitemdisplaystr(SysTableMaps):
                  
                  …
       }
    case MenuItemType::Action:     
            switch (menuItemName)
            {
                case menuitemactionstr(SysCodeExplorer):
                    …
                case menuitemactionstr(xRefUpdate) :
                  …
            }
    } 
 
    Now just write a case for your menuitem depending on the type on the appropriate section
4. You have few variables based on which you could make your decision
   variable: 
   _firstType => has the UtilElementType of the first node selected
 
   Usage: 
    if (_firstType &&
        (_firstType == UtilElementType::Table                 ||
         _firstType == UtilElementType::TableInstanceMethod   ||
         _firstType == UtilElementType::TableStaticMethod     ||
         _firstType == UtilElementType::Macro )
   {
          return 1;
   }  
 
   The menuitem will be enabled only if the  _firstType belongs to any of these specified UtilElementType
 
   variable:
   firstnode  => has the treenode of the first node selected
   Usage:   
   if (firstNode.treeNodePath() == #HelpFilesPath)
  {
        return 1;
  }
 
                 
   Method:
   this.selectionCount() => returns nubmer of node selected
 
   Usage:
  
if(this.selectionCount() >= 1)
  return 1;
 
4.  The object that your menu item is pointing to can have the following code to find the objects that have
been selected
 if (SysContextMenu::startedFrom(args))
 {
      sysContextMenu = args.parmObject();
      treeNode = sysContextMenu.first();
      if (treeNode)
      {
          //Place your code here            
          treeNode = sysContextMenu.first();
      } 
 }
 
5. You can also add items of type MenuReference to your ContextMenu, say you want to have the "GeneralLedger" Module in the ContextMenu, then rightclick select new Menu Reference, you get the link to the module in syscontextmenu…something like this
 
    
 
………  mmm that’s nice right ???

Advertisements
  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: