Search code examples
c#wcfdynamics-crminfinite-loopdynamics-crm-2011

How to prevent infinite looping without ExecutionContext.CallerOrigin in Microsoft Dynamics CRM 2011?


When creating a plugin in Microsoft Dynamics CRM 4.0 you could use the following to check the origin of the event that caused the plugin to fire.

public void Execute(IPluginExecutionContext context)
    {
        if (context.CallerOrigin.GetType() == CallerOrigin.WebServiceApi.GetType())
        {
            return;
        }
        plugin code here...
     }

This would allow you to check if the action was caused by a user in a form, by a web service or a workflow etc...

I have a syncing app that creates and updates entities via WCF, and do not want the plugin executing when this happens, only when users edit entities (to prevent infinite loops in the sync process).

IExecutionContext.CallerOrigin has been removed in MS Dynamics CRM 2011, so what is the new way to do this?

I was thinking that there may be a way to set IExecutionContext.CorrelationId in the WCF calls and then check for it the specific Guid in the plugin, but I haven't had any luck with this yet.


Solution

  • Have you looked inside the IPluginExecutionContext.InputParameters?

    The other option would be to modify your plugin to not update anything if there were no changes, which would prevent the possibility of the infinite loop.