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..
Hi Nishant,
I was trying out your sample of Inactive record plugin (https://nishantrana.wordpress.com/2010/01/29/plug-in-for-setstate-and-setstatedynamicentity-messages/). However when I try to deactivate an record i receive a Syste.OutOfMemeory Execption.
Do you have any idea out it?
LikeLike
Is the state always “Active” and “Inactive”? e.g. when the user’s language is Dutch or French?
LikeLike
Dear Nishant,
can we do the Activate/Deactivate actions on multiple records and use the same plug-in?
i want to prevent users from deactivating multiple records from the grid,
but an error thrown telling that “the selected action was not completed for one or more records.”
what message should i use?
thank you
LikeLike
Very Thanks…
LikeLike