web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

context.userSettings.securityRoles OR Xrm.Page.context.getUserRoles() not working properly

(0) ShareShare
ReportReport
Posted on by 97

Hello Experts,

I have given only the System Admin Security Role to the user. We have some custom Security Roles as well in the system.

what is weird thing is happening that when I retrieved the Security Roles using Javascript Code using context.userSettings.securityRoles OR Xrm.Page.context.getUserRoles() this method 

then it is returning 2 extra Security Roles which user does not have. This is happening on Client Sandbox Org from yesterday. Also, these extra 2 Roles returning for All users. I have tried Checked/Unchecked Security Roles, Even then it is returning extra Roles. These 2 Extra Security Roles are static for all while calling JS method to getting Security Roles.

But I have checked the same JS code on my development org. It is returning proper Roles. Working properly on Development Org.

Thanks in Advance

Shrikant

  • Suggested answer
    Henry J. Profile Picture
    5,237 on at

    Hi Shrikant,

    First, I wouldn't use Xrm.Page.context.getUserRoles as it has officially been deprecated.

    Xrm.Utility.getGlobalContext().userSettings returns the security roles assigned directly to your users but also the roles that the user has inherited through a team membership.
    Have you checked the teams your user belongs to?

    If all users have that role, it is likely that it's been assigned to the business units default teams.

    Henry

  • AJ-22040756-0 Profile Picture
    Microsoft Employee on at

    Hi Partner,

    As rightly said by Henry,  Please check for the roles assigned to the Business Unit or Teams for which the users are a part of as the context.userSettings.securityRoles  will pull all the security roles assigned to Teams for which a user is part of.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
ParthPatel249 Profile Picture

ParthPatel249 64

#2
11manish Profile Picture

11manish 52 Super User 2026 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 44 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans