Search code examples
c#pluginsdynamics-crmcrm

Empty value in attribute | Plugin CRM C#


I change only 1 field in the interface - "telephone1", and leave the second one unchanged, in the end I want field 3 to contain both 1 changed field and 2 field unchanged, but for some reason it is empty, although it contains values, it also works and vice versa. "InputParametres" as I understand it is a bad idea, but what other options are there? https://i.sstatic.net/UUdLn.png

 if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            try
            {
                var createReq = new CreateRequest() { Parameters = context.InputParameters };
                var res = createReq.Target; // Has type Entity
                
                // Получить целевой объект из входных параметров
                Entity entityInput = (Entity)context.InputParameters["Target"];

                // entityInput.Attributes["telephone3"] = entityInput. + ";" + entityInput.Attributes["telephone2"];
                entityInput.Attributes["telephone3"] = res.GetAttributeValue<string>("telephone1") + ";" + res.GetAttributeValue<string>("telephone2");

               // service.Update(entityInput);
            }
            catch (Exception ex)
            {
                throw new Exception($"Error in update telephone3 - {ex.Message}");
            }
        }
        else
        {
            throw new InvalidPluginExecutionException($"Плагин {nameof(Class1)} был зарегистрирован неправильно");
        }

Solution

  • Target will have only changed attributes and it’s values. If you need the values from unchanged attributes (fields) you have to use PreImage to consume them.

    You can register PreImage in Plug-in registration tool similar to steps, filtering attributes, etc.

    Read more