Hi Everyone,
This might be a old one but somehow I could not get this piece code very easily.
Here is the piece of C# code for Associating and Dissociating two records with N:N relationship.
Associate
string relationshipName = "<<RelationShipName>>";
Relationship relationship = new Relationship(relationshipName);
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReference secondaryEntity = new EntityReference("SecondEntitySchemaName", GUIDOfSecondEntityRecord);
relatedEntities.Add(secondaryEntity);
crmService.Associate("FirstEntitySchemaName", GUIDOfFirstEntityRecord, relationship, relatedEntities);
Disassociate
string relationshipName = "<<RelationShipName>>";
Relationship relationship = new Relationship(relationshipName);
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReference secondaryEntity = new EntityReference("SecondEntitySchemaName", GUIDOfSecondEntityRecord);
relatedEntities.Add(secondaryEntity);crmService. Disassociate ("FirstEntitySchemaName", GUIDOfFirstEntityRecord, relationship, relatedEntities);
Hope this helps.
--
Happy 365'ing
Gopinath
This might be a old one but somehow I could not get this piece code very easily.
Here is the piece of C# code for Associating and Dissociating two records with N:N relationship.
Associate
string relationshipName = "<<RelationShipName>>";
Relationship relationship = new Relationship(relationshipName);
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReference secondaryEntity = new EntityReference("SecondEntitySchemaName", GUIDOfSecondEntityRecord);
relatedEntities.Add(secondaryEntity);
crmService.Associate("FirstEntitySchemaName", GUIDOfFirstEntityRecord, relationship, relatedEntities);
Disassociate
string relationshipName = "<<RelationShipName>>";
Relationship relationship = new Relationship(relationshipName);
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReference secondaryEntity = new EntityReference("SecondEntitySchemaName", GUIDOfSecondEntityRecord);
relatedEntities.Add(secondaryEntity);crmService. Disassociate ("FirstEntitySchemaName", GUIDOfFirstEntityRecord, relationship, relatedEntities);
Hope this helps.
--
Happy 365'ing
Gopinath
Wow what a great blog, i really enjoyed reading this, good luck in your work. Pallet Transport Sydney
ReplyDeleteI needed to thank you for this extraordinary Information, I certainly cherished every last piece of it.freight quote
ReplyDelete