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;
}
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:
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156