Hello , Hope Everyone doing very well. i want to share something which a created for you guys. i was working on a requirement where i need to get logged in user security role.Most of you will already know but i discover a new method,a very short code without using any web API . This will help you to save your time to writ a big code.
function getCurrentUserSecurityRoles(executionContext)
{
//Returns information about the current user settings.
var userRoles=Xrm.Utility.getGlobalContext().userSettings;
//it will give you count of security a user is having
if(Object.keys(userRoles.roles._collection).length>0)
{
//userRoles.roles._collection will give you the index of the Current user security role , it contains roleid , and name of the security role
for ( var rolidcollection in userRoles.roles._collection)
{
//Once you get the index of the security role from where you can retrive id, name of the Security Role
var currentUserRoles= Xrm.Utility.getGlobalContext().userSettings.roles._collection[rolidcollection].name;
console.log(currentUserRoles);
}
}
}
If you have any question feel free to ask :).