Introduction
In Dynamics 365 CRM, for certain requirements we need to get user roles so that based on those roles we can show or hide a few fields or some other core logic. As an example, on selected contact record client API user settings present in Xrm.Utility namespace was used.
Step 1
Login to the required environment and select required solution [Contact Customizations Solution in this case] as shown in the below figure.
![Get User Roles with Webresource in Dynamics CRM]()
Step 2
After Step 1, select contact web resource in solution and click on Edit as shown in the below figure.
![Get User Roles with Webresource in Dynamics CRM]()
Step 3
After Step 2, the below code is used to get roles that are present for the logged-in user
Step 4
After Step 3, keep the below code under a method and declare a variable to hold role name that was used to verify and a flag to hold whether the user have given role or not using the below code.
Step 5
After Step 4, final code looks like below
Step 6
After Step 5, save the code and publish the Webresource and open any contact record and observe the popup for the role details as shown in the below figure.
![Get User Roles with Webresource in Dynamics CRM]()
Note:
- Make sure to publish all customizations and upload JavaScript (js) file.
- You can write your logic based on the flag to show few fields and hide few fields for users based on the given requirement.
- Microsoft Documentation link can be found here
Conclusion
In this way, one can easily get roles of the user using Webresource(javascript).