How do I add a CRM plugin step to a many-to-many cross-reference table?

I created a many-to-many relationship between Opportunity and a custom entity. CRM automatically breaks the link to the built-in table known as the Intersection Table .

In the plugin registration tool, I would like to add the โ€œCreate / Update / Deleteโ€ message in this particular table. But the problem is that it does not exist there - even many-to-many systemic relations do not exist there.

People may advise me to manually break up the relationships so that they appear in the registration tool. But are there any solutions to access this inline table?

+4
source share
1 answer

The answer, unfortunately, will not be. The CRM paradigm regarding many tables / relationships is that they are available for Association and Disassociation , but not for Create , Update or Delete queries. (In fact, there are no real Update in the intersection table - new associations are created either only ( Create => Associate ) or dissolved ( Delete => Disassociate ).)

You can verify this in this way by looking at the AttributeMetadata for your intersection object, and you will see that all attributes in your entity have the ValidForUpdateAPI and ValidForCreateAPI set to false. This is different from regular objects that have a combination of attributes that are valid for updating and making calls.

To solve your problem, your options are limited:

1) Register your move against the Association message. This message, unfortunately, cannot be filtered for specific objects, so you will have to filter all requests made in CRM through this plugin. IPluginExecutionContext has a Link property in the InputParameters property InputParameters , which you can use to filter the relationships you want to develop for your code.

 Relationship entityRelationship = (Relationship)context.InputParameters["Relationship"]; if (entityRelationship.SchemaName = customIntersectTable.EntityLogicalName) { EntityReference targetEntity = (EntityReference)context.InputParameters["Target"]; EntityReferenceCollection relatedEntities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"]; //do stuff } 

2) Create a custom intersection object that has one to many relationships with Opportunity and your custom intersection object (similar to something like OpporunityProduct that associates features with products). The disadvantage here is that the GUI for this kind of thing is not as good for this as it is for simple intersection objects.

Gonzalo Ruiz has in this section on MSDN, He pretty much says the same thing.

+5
source

All Articles