This documentation is archived and is not being maintained.

AssignUserRolesRole Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online only

Assigns the specified set of roles to a user.

The relevant classes are specified in the following table.



To use this message, pass an instance of the AssignUserRolesRoleRequest class as the request parameter in the Execute method.

To perform this action, the caller must have access rights on the role entity instance. For a list of required privileges, see AssignUserRolesRole Privileges.


The following code example demonstrates how to assign the specified set of roles to a user.

// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the request object.
AssignUserRolesRoleRequest assign = new AssignUserRolesRoleRequest();

// Set the properties of the request object.
assign.UserId = user.UserId;
// Set the ID of a role that is in the same business unit as the user.
assign.RoleIds = new Guid[] {"B050F053-6968-DC11-BB3A-0003FFBAD37A"};

// Execute the request.
AssignUserRolesRoleResponse assigned = (AssignUserRolesRoleResponse) service.Execute(assign);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create the request object.
Dim assign As New AssignUserRolesRoleRequest()

'Set the properties of the request object.
assign.UserId = user.UserId
assign.RoleIds = New Guid() {"B050F053-6968-DC11-BB3A-0003FFBAD37A"}

' Execute the request.
Dim assigned As AssignUserRolesRoleResponse = CType(service.Execute(assign), AssignUserRolesRoleResponse)

See Also



© 2010 Microsoft Corporation. All rights reserved.