Konrad Viltersten
Konrad Viltersten

Reputation: 39268

Plugin not propagating on field change

I have three entities, let's call them Alpha, Beta and Gamma. There are two plugins registered to trigger on the message Update, both post operation and synchronized.

One of them is invoked when the field aja in Alpha changes and it sets a value of the field baja in any related instance of Beta. The second is invoked when the field baja in Beta changes and it sets a value of the field gaja in any related Gamma.

When I make changes to aja, I can confirm that the update is propagated into all bajas that are in related instances. Corresponding operation on baja updates all related instance's gaja.

What drives me nuts is that a change in aja (which obviously triggers the first plugin causing an update in baja) doesn't trigger the second plugin to set a value in gaja.

I expect a change in Alpha to propagate down to Gamma, because that's how it's supposed to work. I suspect that I'm missing something but after a few attempts, log-checking, crying and swearing, I'm lost. What stupid thing can I be missing?!

Upvotes: 0

Views: 68

Answers (1)

Guido Preite
Guido Preite

Reputation: 15138

The behavior you are facing normally is connected to a IExecutionContext.Depth check

https://msdn.microsoft.com/en us/library/microsoft.xrm.sdk.iexecutioncontext.depth.aspx

Because the plugins are synchronous they run in the current transaction, they cause an increment of the Depth property.

Probably a check like if (context.Depth > 2) { return; } inside your second plugin will solve the problem.

Upvotes: 1

Related Questions