Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 2.44 KB

File metadata and controls

49 lines (37 loc) · 2.44 KB
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
Dynamics 365 Customer Engagement (on-premises)
8976b75c-197d-4d80-b9fe-d4d7a4dfc0f5
18
JimDaly
jdaly
developer

Sample: How to determine whether a user has a role

This sample code is for [!INCLUDEpn_dynamics_crm_online]. Download the complete sample from Work with Users and Roles.

Prerequisites

[!INCLUDEsdk-prerequisite]

Requirements

[!INCLUDEsdk_SeeConnectionHelper]

Demonstrates

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]

Example

[!code-csharpUsersAndRoles#DoesUserBelongToRole1]

Complete Sample Code

[!code-csharpUsersAndRoles#DoesUserBelongToRole]

See also

Privilege and Role Entities
Sample: Remove a Role for a User
User and Team Entities

[!INCLUDEfooter-include]