web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to know if a user has specific privilege in D365 with CODE

(0) ShareShare
ReportReport
Posted on by

Morning, 

Could someone help how to verify if the current user has a specific privilege in D365 using Code please?

I have the same question (0)
  • Suggested answer
    Ramit Paul Profile Picture
    22,797 Most Valuable Professional on at

    Hi,

    Wondering if this is a special requirement to have in CODE level, if not you can easily check the same in security configuration in Sys admin module.

  • Community Member Profile Picture
    on at

    Yes Ramit. Thanks for your reply. Im aware of that functionality in D365.

    But I must do it with code.

    See the process to develop is :  if a user has a privilege AND other condition then a button is enabled.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi,

    You may try some of the code in this thread. It is for AX 2012, but might give you an idea as to how you can achieve this in D365.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    First of all, the button is visible only if the user has a privilege that grants access to it.

    So you don't need to check it in code.

    On top of that, you can still enable/disable it in code, based on your custom logic.

    However as general information there are some ways to evaluate user permissions in code:

    1) You can check in code if an user has access to a menu item button using the AccessRights class but normally you don't need to.

    2) You can query SystemSecurityUserRoleEntity and join it to SystemSecurityPrivilege entity to find out which privileges the current user has access to. Or, use SystemSecurityPermissionEntity to find out on menu item level what is the user's access level.

    But you don't need to! The security framework handles it for you automatically.

  • Suggested answer
    A.Prasanna Profile Picture
    8,223 on at

    just check this out .it may help

    www.axug.com/.../viewthread

    Regards,

    Amith Prasanna

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi Naycene,

    I do agree with Nikolaos here. I wouldn't recommend checking for a privilege. What to do if a copy of that privilege will be created with a small difference? Then you need to change the code to potentially include the new privilege.

    So, best practice: A menu item button would be visible according to settings in the security framework. Based on e.g. status of a record you can have conditions to have a button enabled or disabled.

    If you are using a button and not a menu item button, try to see if you can change it to use the menu item button. Otherwise you need to add form control permissions on the privileges to manage the security.

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    As mentioned by others, this should not be handled by code but a security framework. If you have a menu item button then you can simply create a new privilege only for that menu item.

    If it is the normal button then work with form control permissions, check link docs.microsoft.com/.../how-to-use-roles-and-privileges-to-restrict-access-to-a-button

    www.cloudfronts.com/.../  

  • alexmeyer.itguy Profile Picture
    648 on at

    Naycene,

    The only way to do this via code would be to do it in 3 parts:

    - Get the roles assigned to the user via the SecurityUserRole table

    - Get the role -> subrole -> duty -> privilege security structure from the security framework via the SecurityRepository class

    - Generate a user -> privilege mapping from the above two queries

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans