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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Get Security Roles and Names

(1) ShareShare
ReportReport
Posted on by 42

Hi All

I want to get current user security roles with their names. I'm using Xrm.Utility.getGlobalContext().userSettings.roles.getAll() but unable to get roles and names.

I am not using Model Driven app (Unified Interface). I want to get user roles and names without HTTP Request. Can anyone help me please

I have the same question (0)
  • Anyone Profile Picture
    42 on at
    Get Security Roles and Names

    Hi All

    I want to get current user security roles with their names. I'm using Xrm.Utility.getGlobalContext().userSettings.roles.getAll() but unable to get roles and names.

    I am not using Model Driven app (Unified Interface). I want to get user roles and names without HTTP Request. Can anyone help me please

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Get Security Roles and Names

    This article suggests you may have one too many var stuff = Xrm.Utility.getGlobalContext().userSettings.roles;

    ajitpatra.com/.../

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Get Security Roles and Names

    Hi Partner,

    You need to loop through the returned collection.

    https://staturestack.com/2020/08/06/get-security-roles-of-logged-in-current-user-in-javascript-dynamics-365-ce/

    var roles = Xrm.Utility.getGlobalContext().userSettings.roles;
    
    roles.forEach(function (item) {
        console.log(item.name);
    });

    pastedimage1609231372547v1.png

    I'm not sure whether Xrm.Utility.getGlobalContext().userSettings.roles has been deprecated in legacy web client, you may still need to add an extra HTTP request if the API doesn't work in old UI, because the old API to retrieve security roles only returns collection of GUID.

    https://neilparkhurst.com/2016/08/03/crm2016-javascript-context-object/(See Getting GUID of User Roles section of the article.)

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2015/developers-guide/gg334511(v=crm.7)#getuserroles

    Regards,

    Clofly

  • Anyone Profile Picture
    42 on at
    RE: Get Security Roles and Names

    I'm getting an error "undefined" on roles

    but when i get roles through Xrm.Utility.getGlobalContext().userSettings.securityroles; I am getting only guid not names

  • Anyone Profile Picture
    42 on at
    RE: Get Security Roles and Names

    I'm getting an error "undefined" on roles

    but when i get roles through Xrm.Utility.getGlobalContext().userSettings.securityroles; I am getting only guid not names

  • cloflyMao Profile Picture
    25,210 on at
    RE: Get Security Roles and Names

    Hi Partner,

    If you can only get GUID and Xrm.Utility.getGlobalContext().userSettings.roles doesn't work, you may still need an extra HTTP request.

    Here is sample of combination of Xrm.Utility.getGlobalContext().userSettings.securityroles and HTTP request:

    https://www.c-sharpcorner.com/blogs/to-get-the-list-of-security-roles-assigned-for-logged-in-dynamics-365-user

    Regards,

    Clofly

  • Suggested answer
    Forrest Zhang Profile Picture
    18 on at
    Get Security Roles and Names
    This article may be helpful for you.
     

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 149

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 142

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 125 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans