using System; using Microsoft.Xrm.Sdk; namespace Microsoft.Crm.Sdk.Samples { public class PreEventPlugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); //In this sample, the data to be passed to the post plug-in is // represented by a GUID. Entity contact = (Entity)context.InputParameters["Target"]; Guid contactID = new Guid(contact.Id.ToString()); // Pass the data to the post event plug-in in an execution context shared // variable named PrimaryContact. context.SharedVariables.Add("PrimaryContact", (Object)contactID.ToString()); } } public class PostEventPlugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); // Obtain the contact from the execution context shared variables. if (context.SharedVariables.Contains("PrimaryContact")) { Guid contactID = new Guid((string)context.SharedVariables["PrimaryContact"]); throw new InvalidPluginExecutionException("The value passed from the pre-Event plugin is :" + contactID.ToString()); // Do something with the contact. } } } } //