How to create and delete data from a many-to-many relationship in CRM-2011?

How to create and delete data from a many-to-many relationship in crm 2011?

code:

QueryExpression qry = new QueryExpression(); qry.EntityName = "entity1_entity2"; qry.ColumnSet = new ColumnSet(true); var re = crmservice.RetrieveMultiple(qry).Entities; crmservice.Delete("entity1_entity2", re[0].Id); 

FaultException: The 'Delete' method does not support entities of type 'entity1_entity2'.

+4
source share
4 answers

To link two records using an N: N relationship, you must use Associate / Disassociate or the appropriate service proxy methods.

This will create / delete the corresponding entity1_entity2 object record.

+5
source
 using Microsoft.Crm.Sdk.Messages; ... // get the crm service ... AssociateEntitiesRequest fooToBar = new AssociateEntitiesRequest { Moniker1 = foo, // foo is an entity reference Moniker2 = bar, // bar is an entity reference RelationshipName = "foo_bar", // name of the relationship } service.Execute(fooToBar) // relates foo and bar 

Here is a blog post: http://charithrajapaksha.blogspot.com/2011/08/creating-many-to-many-records-in-crm.html

+4
source

To remove, try below

  // Create an AssociateEntities request. //Namespace is Microsoft.Crm.Sdk.Messages DisassociateEntitiesRequest request = new DisassociateEntitiesRequest(); // Set the ID of Moniker1 to the ID of the lead. request.Moniker1 = new EntityReference { Id = moniker1.Id, LogicalName = moniker1.Name }; // Set the ID of Moniker2 to the ID of the contact. request.Moniker2 = new EntityReference { Id = moniker2.Id, LogicalName = moniker2.Name }; // Set the relationship name to associate on. request.RelationshipName = strEntityRelationshipName; // Execute the request. service.Execute(request); 
+3
source

In an N: N relationship, entries must be linked and separated. You cannot create and delete entries in N: N Relationship. you can use AssociateRequest, DisassociateRequest classes or you can use Associate, Disassociate Messages in the plugin registration tool.

0
source

Source: https://habr.com/ru/post/1390210/


All Articles