protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); tracer.Trace("Inicialize context"); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); //Create an Organization Service tracer.Trace("Inicialize serviceFactory"); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); tracer.Trace("Inicialize orgService"); IOrganizationService orgService = serviceFactory.CreateOrganizationService(context.InitiatingUserId); //Registered Step Guid var pluginStepGuid = Guid.Empty; try { //Plugin Step object tracer.Trace("Inicialize pluginStep"); CrmPluginStep pluginStep = new CrmPluginStep(); pluginStep.PrimaryEntity = PrimaryEntity.Get <string>(executionContext); tracer.Trace("PrimaryEntity: " + pluginStep.PrimaryEntity); pluginStep.PluginAssemblyName = AssemblyName.Get <string>(executionContext); tracer.Trace("PluginAssemblyName: " + pluginStep.PluginAssemblyName); pluginStep.EventHandler = EventHandler.Get <string>(executionContext); tracer.Trace("EventHandler: " + pluginStep.EventHandler); pluginStep.Mode = Mode.Get <int>(executionContext); tracer.Trace("Mode: " + pluginStep.Mode); pluginStep.Rank = Rank.Get <int>(executionContext); tracer.Trace("Rank: " + pluginStep.Rank); pluginStep.FilteringAttributes = FilteringAttributes.Get <string>(executionContext); tracer.Trace("FilteringAttributes: " + pluginStep.FilteringAttributes); pluginStep.InvocationSource = InvocationSource.Get <int>(executionContext); tracer.Trace("InvocationSource: " + pluginStep.InvocationSource); pluginStep.Stage = Stage.Get <int>(executionContext); tracer.Trace("Stage: " + pluginStep.Stage); pluginStep.Deployment = Deployment.Get <int>(executionContext); tracer.Trace("Deployment: " + pluginStep.Deployment); pluginStep.Message = Message.Get <string>(executionContext); tracer.Trace("Message: " + pluginStep.Message); pluginStep.Name = pluginStep.EventHandler + ": " + pluginStep.Message + " of " + pluginStep.PrimaryEntity; tracer.Trace("Name: " + pluginStep.Name); pluginStep.tracer = tracer; tracer.Trace("--- Register Plugin Step --- "); //Register Step pluginStepGuid = pluginStep.RegisterPluginStep(ref orgService); tracer.Trace("pluginStepGuid: " + pluginStepGuid); PluginStepGuid.Set(executionContext, pluginStepGuid.ToString()); } catch (Exception e) { throw new InvalidPluginExecutionException("(RegisterPluginStep) Error! " + e.Message); } }