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 :
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,755 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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans