Monday, January 17, 2011

How to check where your CRM 4.0 Plugin is being called from

Recently, I needed to figure out if a CRM 4.0 Plugin was being called from CRM or whether it was being called from the CRM API.

Luckily, the context provides this information through the context.CallerOrigin property. You can use this to determine whether the plugin is being called by comparing the type of the property to the following types:

if(context.CallerOrigin Is ApplicationOrigin) // It's being called from the CRM Web Application

if(context.CallerOrigin Is AsyncServiceOrigin) // It's being called from the Async Process

If(context.CallerOrigin Is WebServiceApiOrigin) // It's being called from external to CRM Via Web Services.

So there you have it...