Trigger plugin for N:N relationships in Dynamics CRM

Image Posted on

Yesterday I was working on a requirement to trigger a plugin for N:N relationship. The idea is as soon as a record on N:N subgrid is added, trigger the plugin. Follow steps below for this –

1. Create a PreUpdate plugin on the entity

2. Check Message Name in from the PluginExecutionContext. Use Associate if checking for addition of a record in N:N or Disassociate for deletion of record in N:N

3. Validate Context depth is 1, this is to avoid recursive / infinite loops

4. Use “Relationship” input parameter to get current entity

5. Use Relation Entity schema name to get related entity record. This can be found by opening the respective N:N relationship.

6. Ensure the Plugin is registered with following values –




Code snippet below –


Hope it helps..