Hi , i have a form in the Account entity which contains an email field and two option field called "Email Approve", when i update the email field it doesn't work, but when i update the "Email Approve" it works. The plugin is raised when an update happens to another "Email Approve" field in Case entity on Post Operation. Here is the code:
public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = serviceProvider.GetService(typeof(ITracingService)) as ITracingService; IPluginExecutionContext context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext; IOrganizationServiceFactory serviceFactory = serviceProvider.GetService(typeof(IOrganizationServiceFactory)) as IOrganizationServiceFactory; IOrganizationService organizationService = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("context message:{0}",context.MessageName); if (context.MessageName.ToLower() == "update") { if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity currentCaseEntity = context.InputParameters["Target"] as Entity; tracingService.Trace("entity logical name is :{0}", currentCaseEntity.LogicalName); if (currentCaseEntity.LogicalName == "incident") { try { if (currentCaseEntity.Attributes.Contains("new_emailapprove")) { bool emailAprrove = currentCaseEntity.GetAttributeValue<bool>("new_emailapprove"); tracingService.Trace("email approve value :{0}", emailAprrove); if (emailAprrove) { Entity preImageCaseEntity = context.PreEntityImages["preImageCaseEntity"]; EntityReference associatedAccountReference = preImageCaseEntity.GetAttributeValue<EntityReference>("customerid"); Entity associatedAccount = organizationService.Retrieve( associatedAccountReference.LogicalName, associatedAccountReference.Id, new ColumnSet(true)); tracingService.Trace("account name : {0}",associatedAccount["name"]); associatedAccount["new_emailapprove"] = true; associatedAccount["new_email"] = "someemail@test.com"; tracingService.Trace("account email after updated: {0}",associatedAccount["new_email"]); organizationService.Update(associatedAccount); } } } catch (Exception e) { throw e; } } } } }