Access on command button


I am working in Ax 2012. I have a question regards access and security. I have a Actionpane on the form. Within this actionPane there is a buttongroup and within that button group, there is a command button.

I do want to set the access of command button for the accountant role. Only Accountant role can view it, not anyone else.

How can I do it?


You posted this in the wrong forum - this is the Nav developers forum

Moved to AX Developer forum.


First you need to create a separate user for accountant role. Then right code below in a init method at a form level

public void init()



if( curUserId() == “Accountant name”)









Definitely don’t hard-wire employee IDs in code, as somebody suggested.

I believe you have to choose one of two ways:

  1. Either you can map the command button to an access level, e.g. Delete.
  2. Or you have to map the action as a new entry point, i.e. a menu item.

It’s unusual to do such things with command buttons, they’re typically used for something related to the form itself (closing, exporting to Excel…) which is not related to security or for manipulation of records (creating, deleting…) and that uses the table-level security.

Your concern is obvious…

But by using the above code we are just authenticating the user which is already set up in a AX user group to use the command button in a single step.

And the user who is authenticated by admin will only be able to change that.

And yes, it is unusual to do such things with command buttons, if we really need that, then it must be done using classes to have extra security.

NEVER hardcode security the way Mohd advised…!!! This will fail on the first audit of the system by external auditors… Microsoft did not invent that complex security system in AX 2012 for no reason so that you could start writing code structures like “if( curUserId() == “BOSS”) Object.visible(true);”.

And what if that employee will be fired and new one will come instead? Will you modify then? Will you modify the code in situation which should have been just a pure administrative settings change?

What if there will be 100 users who might need the same access level?? Will you write a huge “IF” statement like this: if (curUserId() == “ABC” || curUserId() == “DEF” || … ) ???

Sorry for being so offensive, but I haven’t said anything wrong…

hey, easy my freind, I have just written that code for testing purpose. I have not written anywhere that it is good in terms of security…

Just create user group. Then you can use “if” . if somebody go/in, you can add them to that user group.