Skip to main content

Notifications

Service | Customer Service, Contact Center, Fie...
Answered

User Security Roles and Team Security Roles

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
    Community Member Microsoft Employee 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans