Monday, February 04, 2008

Entity Relationships in MS CRM 4.0

Dear Programmers,

here is some stuff for you, I was working on Entity relationships of MS CRM 4.0, how you will use and how you will work with them,

1. One-to-Many System-System (1:n)

In CRM 4.0 you can link system entity to another system entity. The child system entity has a lookup field to associate it with a parent system entity.

2. Self-Referential

In CRM 4.0 you can link An entity to itself. For example a Case can be linked to a master Case.

3. Multiple Relationships Between Entities

Many of you know about mulitple lookups issues with same entity, now it can be achieved in MS CRM 4.0 e.g the Account entity might have two relationships with a Contact entity - a primary and secondary Contact.

4. Many-to-Many System-System, System-Custom & Custom-Custom (n:n)

In CRM 4.0 this is major requirement for many to many relationship, now it is possible . Not only will this remove the need to build a “joining” entity, but you have control over how the relationships show up in the UI.

Here is sample code how to associate many to many in MS CRM Code.

// 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 = EntityName.contact.ToString();

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

// Execute the request.

service.Execute(request);


Happy Programming with MS CRM

REgards,
Imran