Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Sample code to get rolename based on userid provided.

Posted on by

Hello All Experts,

I want to get the Role Name using c# code based on userid provided .

how to get it.

can anyone provide me with a sample code.

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Sample code to get rolename based on userid provided.

    Hi,

    Please refer the links below. It gives C# code for getting security role of the user.

    worldofdynamics.blogspot.in/.../retrieve-user-security-roles-code.html

    mscrmtechie.blogspot.in/.../checkget-user-security-role-in-crm.html

    Hope this helps.

  • Suggested answer
    SCV Profile Picture
    SCV 1,004 on at
    RE: Sample code to get rolename based on userid provided.
    Hi,

    Using early bound classes you can achieve this using this method.


    public void GetSecurityRolesOfTheUser(XrmServiceContext serviceContext, Guid userid) { var systemUserRoles = (from ur in serviceContext.SystemUserRolesSet join r in serviceContext.RoleSet on ur.RoleId equals r.RoleId where ur.SystemUserId == userid select r.Name).ToList(); }


     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans