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 :
Service | Customer Service, Contact Center, Fie...
Answered

User Security Roles and Team Security Roles

(0) ShareShare
ReportReport
Posted on by 30

I'm trying retrieve the only User Security roles, but below code is retrieving the user security roles and team security roles as well. I want only User Security Roles.

Can we filter logged in user security roles, in MSCRM?


function GetUserRole() {

    var roles = Xrm.Utility.getGlobalContext().userSettings.roles;
    var hasRole = true;
    roles.forEach(function (item) {
        if (item.name.toLowerCase() === "technical team-security role") {
            hasRole = false;
        }
    });
 
    return hasRole;
}

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: User Security Roles and Team Security Roles

    Hi Banne,

    You could use this code to get only user's security roles:

    function onchange(){
    	var userId = Xrm.Utility.getGlobalContext().userSettings.userId.replace('{','').replace('}','');
    	Xrm.WebApi.retrieveMultipleRecords('systemuserroles', '?$filter=systemuserid eq '   userId).then(
    	function success(result){
    		var entities = result.entities;
    		entities.forEach(function(item){
    			console.log(item);
    		})
    	}, 
    	function fail(error){
    		console.log(error.message)
    	});
    }

    It's result would be like this:

    pastedimage1651571860393v1.png

    If you know the specific roleid, you could directly compare roleid. If no, you need to get role name by role id and then compare.

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 36 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans