Get Logged In User Security Roles in Dynamics 365 v9.1

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
		//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;    

If you have any question feel free to ask :).

Author: Surya Pratap Singh

I am a Dynamics 365 Sales Functional Consultant Associate|MCSE|MCSA|MCP.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s