title | description | ms.custom | ms.date | ms.reviewer | ms.suite | ms.tgt_pltfrm | ms.topic | applies_to | ms.assetid | caps.latest.revision | author | ms.author | search.audienceType | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Sample: Determine whether a user has a role (Developer Guide for Dynamics 365 Customer Engagement) | MicrosoftDocs |
The sample shows how to determine whether a user in Dynamics 365 Customer Engagement has been associated with a specific role. |
10/31/2017 |
pehecke |
sample |
|
8976b75c-197d-4d80-b9fe-d4d7a4dfc0f5 |
18 |
JimDaly |
jdaly |
|
This sample code is for [!INCLUDEpn_dynamics_crm_online]. Download the complete sample from Work with Users and Roles.
[!INCLUDEsdk-prerequisite]
[!INCLUDEsdk_SeeConnectionHelper]
This sample shows how to determine whether a user in [!INCLUDEpn_microsoftcrm] has been associated with a specific role. This is performed by using a query with the xref:Microsoft.Xrm.Sdk.IOrganizationService.xref:Microsoft.Xrm.Sdk.IOrganizationService.RetrieveMultiple* method. A snippet that shows the key sections of the sample is shown first, followed by the complete sample code. Note that this sample can only be run in an on-premises environment because it creates a user. However, the section of the sample that demonstrates retrieving the roles for a user will work for all environments.
[!INCLUDEcc_sdk_onpremises_note]
[!code-csharpUsersAndRoles#DoesUserBelongToRole1]
[!code-csharpUsersAndRoles#DoesUserBelongToRole]
Privilege and Role Entities
Sample: Remove a Role for a User
User and Team Entities
[!INCLUDEfooter-include]