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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Get user roles using x++

(0) ShareShare
ReportReport
Posted on by 435

Hi All,

How to get current user roles via X++.

I have tried below code but this shows one role only.But i have three roles.

SecurityRole        role;
     SecurityUserRole    userRole;
     UserInfo            userInfo;
     ;

 
    while select firstonly  role
    exists join userRole
    where role.RecId     == userRole.SecurityRole
          && userRole.User == curUserId()
  {
    info(strFmt("%1  -  %2", role.Name,curUserId()));

}

Please suggest.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Ajit Profile Picture
    8,788 on at

    Remove the keyword 'firstonly' and then try.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Your immediate requirements to just list the roles can be addressed as Ajit has recommended.

    Please note that security roles associated with a user are not the only configuration that drive that what does a user have access to, because you could also define overrides, or which companies can a user have access for.

    Also this topic has been asked in the forums many times, you can find collection and references of posts with various solutions if you follow the links there, for example in this thread:

    community.dynamics.com/.../105442

  • Vilmos Kintera Profile Picture
    46,149 on at

    Can you please make sure you tick the checkboxes for helpful answers next to each post, so the topic gets resolved? Thank you.

  • Venkygeorge Profile Picture
    60 on at

    Hello,

    Try below code this will shows all the roles from Ax, which you are assigned to the current user.

    static void LTRoles(Args _args)
    {
        SecurityRole        role;
        SecurityUserRole    userRole;
        UserInfo            userInfo;
     
        while select * from role
            exists join userRole        
            where role.RecId == userRole.SecurityRole
            && userRole.User == curUserId()
        {
            info(strFmt("%1  -  %2", role.Name,curUserId()));
        }

    Here i have assigned 4 roles for current user (ith.ax.d)
        O/P:
        System administrator  -  ith.ax.d
        System user  -  ith.ax.d
        ESS PMS  -  ith.ax.d
        EP PMS  -  ith.ax.d
    }
    Regards

    Venky George.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans