API to get Logged In User’s security role(s) name and ID in Dynamics 365 – Xrm.Utility.getGlobalContext().userSettings.roles. API bug has been fixed. Team role name no longer come as undefined.

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com
It feels great to write this post. Not because this the first time I am writing this post. But because last time when I wrote a post about this, there existed a bug in the API because of which some customers had to back out from using it.
Well Microsoft recently introduced a new method in it’s client client API which will give logged in user’s security role with both the id and name. The API is Xrm.Utility.getGlobalContext().userSettings.roles.
I have described it here. It was a great delight for everyone because the prior API’s would just provide the security role id and then again to get the role names to needed to perform a second query to Dynamics 365/ CDS database.
But the initial introduction of the function had a major bug. While it was giving the security role names correctly for all the roles directly assigned to the user, for the team roles, the name was coming as undefined.


image
Well no more. It feels great to say that as committed by Microsoft, the bug has been fixed. If I now use the API, the security role names are coming fine even for the team roles.
image
Here CEO Business Manager security role is assigned to a team to which the logged in user belongs.
A great sense of relief for everyone I guess.
Hope this helps!
Debajit Dutta
(Business Solutions MVP)