We need to restrict some delete operations done automatically from Outlook towards CRM 2011 while we wait for a bug fix in a 3rd party addin. Is it possible to have a plugin in Dynamics CRM 2011 on-premise that either only executes for the Outlook client (offline not in use) or that checks in the execution if the plugin is triggered from Outlook?
In CRM 4.0 there used to be a CallerOrigin property that gave at least some information on this, but that property is now seemingly only internal in the CRM 2011 model.
I accessed CallerOrigin
by reflection (it is still there, but not exposed in the SDK libraries).
The code below is a short version of my code, without any validations or null checks (i.e. not production code) just to show how it works in a few lines:
object callerOrigin = context.GetType().GetProperty("CallerOrigin").GetValue(context, null);
return callerorigin.GetType().Name; // will return "WebServiceApiOrigin" if called from outlook or web services
There are two properties on the IExecutionContext that you should be aware of when writing plugins to run offline in Outlook:
IExecutionContext.IsExecutingOffline indicates whether the plugin is running in Outlook while offline, and:
IExecutionContext.IsOfflinePlayback indicates that the plugin is being fired when changes made whilst Outlook client was offline are being played back when the client connects to the server again and sync the changes with the server.