Hi I'm very new with CRM Development and C#. I'm creating this synchronous plugin which runs in Pre-Validation stage(not sure of right) On creating an account, when user enters/choose a ZipCode , I want the region number and county number to be populated based on the ZipCode. The relationship between zipcode, region and county are already set on CRM. Zipcode, region and county are an Entity and a lookup on the Account form. Please help me , i'm getting an error : "An error occurred in entity plug-in" Here is my code: if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName == "account") { if (entity.Attributes.Contains("abc_zippostal")) { try { EntityReference zipcode = (EntityReference)entity.Attributes["abc_zippostal"]; if (zipcode != null) { var zipId = zipcode.Id; Entity zipEntity = service.Retrieve("abc_zipcode", zipId, new ColumnSet("abc_regionid", "abc_countyid")); Guid contyId = zipEntity.GetAttributeValue ("abc_countyid").Id; EntityReference countyId = (EntityReference)zipEntity.Attributes["abc_countyid"]; EntityReference regionId = (EntityReference)zipEntity.Attributes["abc_regionid"]; entity.Attributes["aa_countynumberid"] = new EntityReference("aa_county", countyId.Id); entity.Attributes["aa_countynumberid"] = new EntityReference("aa_region", regionId.Id); service.Update(entity) Thanks in advance!
↧