Wednesday, May 21, 2014

CRM - Handling Plugin Messages

In CRM when creating we will be handling multiple messages. I am trying to put different approaches we have to take based on messages in a single place. 


  • Update

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
Entity entity = (Entity)context.InputParameters["Target"];

  • Associate/Disassociate

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
EntityReference entityReference = (EntityReference)context.InputParameters["Target"];
if (context.InputParameters.Contains("Relationship"))
{
string relationshipName = context.InputParameters["Relationship"].ToString();
if (relationshipName == "relationshipnametocheck")
{}}}

   Reference.                     

  • SetState/SetStateDynamicEntity

if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference)
EntityReference entityReference = (EntityReference)context.InputParameters["EntityMoniker"];

If we have to trigger a plugin when a record status changes, its advisable to register the same for both tthe SetState and SetStateDynamicEntity. The reason why both the messages are required is both messages perform the same action in CRM and as there is not thumb rule for which action which message is fired, its better to register the plugin for both messages so that our plugin works properly. Reference.

No comments:

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...