Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 2.19 KB

sample-associate-security-role-user.md

File metadata and controls

53 lines (40 loc) · 2.19 KB
title description keywords ms.date ms.custom ms.topic applies_to ms.assetid author ms.author ms.reviewer ms.suite ms.tgt_pltfrm caps.latest.revision topic-status search.audienceType
Sample: Associate a Security Role to a User (Developer Guide for Dynamics 365 Customer Engagement) | MicrosoftDocs
The sample shows how to associate a role with a user by using the IOrganizationService.EntityReferenceCollection) method.
10/31/2017
sample
Dynamics 365 Customer Engagement (on-premises)
c962101c-65f0-4e49-8c23-99c2a9e7dcbf
JimDaly
nabuthuk
pehecke
17
Drafting
developer

Sample: Associate a Security Role to a User

This sample code is for [!INCLUDEpn_dynamics_crm_online].

Prerequisites

[!INCLUDEsdk-prerequisite]

Requirements

[!INCLUDEsdk_SeeConnectionHelper]

Demonstrates

This sample shows how to associate a role with a user by using the xref:Microsoft.Xrm.Sdk.IOrganizationService.xref:Microsoft.Xrm.Sdk.IOrganizationService.Associate* method. A snippet showing just the key portions 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 associating a role with a user will work for all environments.

[!INCLUDEcc_sdk_onpremises_note]

Example

[!code-csharpUsersAndRoles#AddRoleToUser1]

Complete Sample Code

[!code-csharpUsersAndRoles#AddRoleToUser]

See also

Privilege and Role Entities
Sample: Determine Whether a User has a Role
User and Team Entities
xref:Microsoft.Xrm.Sdk.IOrganizationService

[!INCLUDEfooter-include]