Tuesday, 16 February 2016

Plugin on State change on record

 public class MYcust : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;
            // In case of SetState and SetStateDynamicEntity message InputParameter
            // would contain EntityMoniker parameter
       
            if (context.InputParameters.Contains("EntityMoniker") &&
            context.InputParameters["EntityMoniker"] is EntityReference)
            {
                EntityReference ef = (EntityReference)context.InputParameters["EntityMoniker"];

                throw new InvalidPluginExecutionException("Record can't be activated");// 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");
                //}
            }
        }
    }

No comments:

Post a Comment