Friday 13 September 2013

Associate Request MSCRM 2011

Scenario: I have 2 Entity "Entity A" and Entity B", and there is a relationship 1:N between "Entity A"and "Entity B".Suppose you have create a new record for "Entity A"and since there is a relationship between "Entity A"and "Entity B", so you would like to relate this "Entity A" record to a specific or many records of "Entity B". I will use a class called “Associate Request”  which links records to each user assuming there is a relationship between the entities which records belong to . Below is the code snippet to achieve:



IOrganizationSericce service;  // instance of the organization serivce
AssociateRequest  contactToAccount = new AssociateRequest
 {

//Entity A Record
Target = new EntityReference(Entity A LogicalName, Entity A.GUID),
RelatedEntities = new EntityReferenceCollection
 {
 new EntityReference(Entity B LogicalName, Entity B.GUID)
 },

Relationship = new Relationship(“name of the relationship already existing”)
 };

              

Thanks.. :)
 

No comments:

Post a Comment