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

Announcements

No record found.

News and Announcements icon
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;
}

  • Verified answer
    Community Member Profile Picture
    on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
11manish Profile Picture

11manish 44 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 41

#3
Ayesha Wajahat Profile Picture

Ayesha Wajahat 18

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans