Out of the box API to get Logged In user’s security role names in Dynamics 365 is finally there. Is the long wait finally over?

Checking for logged in user’s security role is a requirement I haven’t missed in any of my implementations so far. From enterprise implementations to projects spanning couple of months, this requirement I had everywhere. And as much crazy it may sound, until recently there was no way to get the security role names directly using client API. Even the unified interface introduced Xrm.Utility.getGlobalContext().userSettings.securityRoles which unfortunately had the same perennial problem – we shall get a the GUID of the roles user is having and then we have to fire a query to the server side to get the role names.

Thankfully Microsoft have slipped in an update to get the role names. Since this one came without much publicity, it didn’t get the media attention it deserved. Microsoft have deprecated – Xrm.Utility.getGlobalContext().userSettings.securityRoles and instead suggested to use Xrm.Utility.getGlobalContext().userSettings.roles. Use the getAll() function to take the output as array.


As seen from the developer console, it’s a relief certainly. We no longer need to query the separately to get the role names. Wonderful isn’t it. Finally a solution to a long standing problem? Well not exactly.


This method works just fine if you have the security roles directly assigned to the user. However if the user is added to a team and the team have a security role, the name comes as undefined.


Above is a screenshot for a user. The user is assigned to a team and the team is having Sales Manager role. Although the API is indeed returning the GUID of all the roles, the name of the security role coming through team association is coming as undefined.

Honestly I was bit surprised as it is kind of quite basic and this making the final cut with this issue is something I was not expecting.

I hope this is fixed quick by Microsoft.

Till then we wait with bated breath to use this for all scenarios.


Hope this helps!

Published by


I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

4 thoughts on “Out of the box API to get Logged In user’s security role names in Dynamics 365 is finally there. Is the long wait finally over?”

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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