Tuesday, 15 March 2011

How to use a common plugin for Create / Update /Delete events

Its possible to use a common plugin to handle Create / Update / Delete events of an entity.
Code snippet:

context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.InputParameters.Contains("Target") &&

context.InputParameters["Target"] is Entity)
{
  
 if (context.MessageName == "Create")
 {
//Code to be executed during Create event of an entity
}

   if (context.MessageName == "Update”)
{
//Code to be executed during Update event of an entity
}

}

MessageName is assigned when we create step by using Plugin registration tool as shown.
Above code shows how to differentiate between the Create and Update events.
Delete event works in a different way. Please refer the following link
http://crmdm.blogspot.com/2011/03/delete-event-is-not-firing-in-crm-2011.html

No comments:

Post a Comment