AssociateEntities Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment types Works online and offline

Adds a link between two entity instances in a many-to-many relationship.

The relevant classes are specified in the following table.

Type Class
Request AssociateEntitiesRequest
Response AssociateEntitiesResponse


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

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


The following code example demonstrates how to add a link between two entities that participate in a many-to-many relationship.

// 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 an AssociateEntities request.
AssociateEntitiesRequest request = new AssociateEntitiesRequest();

// Set the ID of Moniker1 to the ID of the lead.
request.Moniker1 = new Moniker();
request.Moniker1.Id = new Guid("B050F053-6968-DC11-BB3A-0003FFBAD37A");
request.Moniker1.Name = EntityName.lead.ToString();

// Set the ID of Moniker2 to the ID of the contact.
request.Moniker2 = new Moniker();
request.Moniker2.Id = new Guid("1DCDEE97-35BB-44BE-8353-58BC36592656");
request.Moniker2.Name =;

// Set the relationship name to associate on.
request.RelationshipName = "contactleads_association";

// Execute the request.

[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 an associateEntities Request.
Dim request As New AssociateEntitiesRequest()

' Set the id of moniker1 to the id of the lead
request.Moniker1 = New Moniker()
request.Moniker1.Id = New Guid("B050F053-6968-DC11-BB3A-0003FFBAD37A")
request.Moniker1.Name = EntityName.lead.ToString()

' Set the id of moniker2 to the id of the contact
request.Moniker2 = New Moniker()
request.Moniker2.Id = New Guid("1DCDEE97-35BB-44BE-8353-58BC36592656")
request.Moniker2.Name =

' Set the relationship name to associate on
request.RelationshipName = "contactleads_association"

' Execute the request

See Also



© 2010 Microsoft Corporation. All rights reserved.