Skip to main content

Notifications

Dynamics 365 Community / Forums / Sales forum / Get Security Roles and...
Sales forum
Suggested answer

Get Security Roles and Names

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

  • Suggested answer
    Forrest Zhang Profile Picture
    Forrest Zhang 16 on at
    Get Security Roles and Names
    This article may be helpful for you.
     
  • cloflyMao Profile Picture
    cloflyMao 25,196 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

  • Anyone Profile Picture
    Anyone 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
    Anyone 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

  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,196 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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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/.../

  • Anyone Profile Picture
    Anyone 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

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

News and Announcements

Forum Structure Changes Coming Soon!

Quick Links

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,734 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,021 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,150

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans