Adding new feature to context menu for AOT objects in AX 2012

Continue reading

Sometimes there is a need to add new feature to standard context menu. Let’s assume that we want in a quick way change the developer’s startup project.

Instead of manual changing it in  Tools->Options form, we would like have a possibility to setup it when we right click over the project’s object in Projects window. This could be done in a few steps described below.

Create the class with the feature’s code. To make a solution bit a flexible let’s assume that updating the startup project will be first of several additional features.

Prior to creating class we will create the base enum for menu items:

ANG_ContextMenuItem with element UpdateStartupProject:

Now let’s create the class ANG_ContextMenu with method openStartupProject:

class ANG_ContextMenu



public static ANG_ContextMenu construct()


return new ANG_ContextMenu();


public static void main(Args _args)


ANG_ContextMenu contextMenu = ANG_ContextMenu::construct();

if (_args.parmEnumType() == enumNum(ANG_ContextMenuItem))




public void run(Args _args)


switch (_args.parmEnum())


case ANG_ContextMenuItem::UpdateStartupProject :





private void updateStartupProject(Args _args)


UserInfo userInfo;

UtilElementName startupProj;

SysContextMenu contextMenu;

TreeNode treeNode;

if (SysContextMenu::startedFrom(_args))


contextMenu = _args.parmObject();

treeNode = contextMenu.first();

startupProj = treeNode.treeNodeName();

update_recordSet userInfo

setting StartupProject = startupProj

where == curUserId();



Create the menu item ANG_UpdateStartupProject for the feature with the properties as is displayed below:

Add the menu item to SysContextMenu menu:

So now it could be visible in context menu:

In the SysContextMenu class we need to modify method verifyItem() to prevent running the feature for other types of AOT objects. We can achieve this by adding below code to the last switch clause in the method:

case menuitemActionStr(ANG_UpdateStartupProject):

if ( firstNode.handle() == classNum(ProjectNode) && //Only launch from project node



return 1;


return 0;

So now we have a new menu item in context menu with possibility to add other usable features in a simple way.

More articles
Explore our blog

What can we do for you?

We'd love to hear about your project. Our team will get back to you within two working days.

Thank you for inquiry, we’ve passed it to our sales department, our representative will reach you back in his earliest convenience.
Oops! Something went wrong while submitting the form.