Plug-in for SetState and SetStateDynamicEntity messages.
Views (4501)
Hi, If we want to write a plugin that would run in case of state change of an entity record, we need to attach that plugin to both setstate and setstatedynamicentity messages.
Here is a sample plugin that would prevent an inactive contact record from getting activated.
Plugin has been registered against contact entity and two steps have been registered one on setstate and other on setstatedynamicentity messages on Pre event.
public void Execute(IPluginExecutionContext context) { // In case of SetState and SetStateDynamicEntity message InputParameter // would contain EntityMoniker parameter Moniker entity = null; if (context.InputParameters.Properties.Contains("EntityMoniker") && context.InputParameters.Properties["EntityMoniker"] is Moniker) { entity = (Moniker)context.InputParameters.Properties["EntityMoniker"]; // Get the state to which record is to be changed // If Active the record is being activated // If Inactive the record is being deactivated string state= (string)context.InputParameters.Properties[ParameterName.State]; // Verify that the entity represents an account. if (entity.Name == EntityName.contact.ToString() && state=="Active") { throw new InvalidPluginExecutionException("Record can't be activated"); } } }Bye..
Filed under: CRM, Microsoft Dynamics CRM Tagged: CRM 4.0![]()
![]()
![]()
![]()
![]()
![]()
![]()
This was originally posted here.

Like
Report
*This post is locked for comments