Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

How to get record owner's security role with JavaScript?

Posted on by 353
Hello,
 
The current user's can be retrieved easily, but how can I get the record owner (also a CRM user) role with JS code?
 
Thanks.
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    How to get record owner's security role with JavaScript?
    Hi,
     
    You can use the following code to get the security roles of the record owner.
     
    Xrm.WebApi.retrieveMultipleRecords("systemuser", "?$filter=fullname eq '<CRM User Name>'&$select=fullname&$expand=systemuserroles_association($select=name)").then(
        function success(result) {
            var securityRoles = result.entities[0].systemuserroles_association;
            for (var i = 0; i < securityRoles.length; i++) {
                console.log(securityRoles[i].name);
            }  
           
        },
        function (error) {
            console.log(error.message);
        }
    );
     
    In my testing, I was the System Administrator, and the owner of the records was me.
    The security roles I get using the code provided above are the same as the officially provided API: Xrm.Utility.getGlobalContext().userSettings.roles.
     
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans