Hi World,
I triying to copy a value from OptionSet field to number Field
This is my plugin code
public void Execute(IServiceProvider serviceProvider) { // Contexto del plugin. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { //Obtenemos la entidad "Contacto" que viene de los parametros de entrada (Target). Entity contacto = (Entity)context.InputParameters["Target"]; // Interfaz de CRM para las consultas. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { Entity preImage = (Entity)context.PreEntityImages["preImage"]; Entity contactoCrm = service.Retrieve("contact", contacto.Id, new ColumnSet("clk_customtype", "clk_customtypename", "clk_customtypevalueflow")); string customType = contactoCrm.Attributes.Contains("clk_customtypename") ? contactoCrm["clk_customtypename"].ToString() : string.Empty; // Si el contexto trae el CustomType, es porque lo acabaron de cambiar. if (contacto.Attributes.Contains("clk_customtypename")) { customType = contacto["clk_customtypename"] != null ? contacto["clk_customtypename"].ToString() : string.Empty; } if (string.IsNullOrEmpty(customType)) { throw new InvalidPluginExecutionException("Validación de negocio: El CustomType del cliente se encuentra vacÃo."); } if (!string.IsNullOrEmpty(customType)) { int newCustomType = Int32.Parse(customType); contactoCrm.Id = contacto.Id; contactoCrm["clk_customtypevalueflow"] = newCustomType; } service.Update(contactoCrm); } catch (InvalidPluginExecutionException e) { throw e; } catch (FaultException ex) { string error = ex.ToString(); throw new InvalidPluginExecutionException(ex.Message); } catch (Exception e1) { throw new InvalidPluginExecutionException(e1.Message, e1); } } }
and this my result
Plugin Trace: [ClickaliaTest: ClickaliaTest.ActualizarContacto] [b76f39fb-ab03-ec11-b6e7-000d3ac1ab43: ClickaliaTest.ActualizarContacto] Error Message: Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault] Message: The given key was not present in the dictionary.Detail: d8ea166e-54c2-4c2b-8478-ceee99d88669 -2147220891 OperationStatus 0 SubErrorCode -2146233088 Plugin.ExceptionFromPluginExecute ClickaliaTest.ActualizarContacto Plugin.ExceptionRetriable false Plugin.ExceptionSource PluginExecution Plugin.OriginalException PluginExecution Plugin.PluginTrace http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException:80040265&client=platform The given key was not present in the dictionary. 2021-08-23T03:07:15.4119533Z false PluginExecution PluginExecution [ClickaliaTest: ClickaliaTest.ActualizarContacto] [b76f39fb-ab03-ec11-b6e7-000d3ac1ab43: ClickaliaTest.ActualizarContacto]
So, someone tell me What are doing wrong?
Thanks a lot