Ivan Jovović
Ivan Jovović

Reputation: 5298

Dynamics CRM 2011 plugin set custom field value

I have Dynamics CRM 2011 plugin (retrieve, post-action) which should simply set the value of custom field when retrieving Contact entity:

    public void Execute(IServiceProvider serviceProvider)
    {            
        IPluginExecutionContext context = PluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));            
       if (context.OutputParameters != null)
       {
          Entity entity = (Entity)context.OutputParameters["BusinessEntity"];
          if (entity.Attributes.ContainsKey("new_markerexists") == false)
                return;
          entity["new_markerexists"] = "Marker exists.";

However, CRM plugin can not find this or any other custom field. It works fine with the standard fields.

What am I missing here?

Thanks!

Upvotes: 0

Views: 2841

Answers (2)

Zeeshan Ahmed
Zeeshan Ahmed

Reputation: 193

If your custom field is empty then it will not add the field in the attribute collection. If you want to get the Custom field you will must have to provide some value to it. I have tested and it is working.

Upvotes: 1

Ivan Jovović
Ivan Jovović

Reputation: 5298

As stated here: https://stackoverflow.com/a/9903306/1023562

In CRM, only properties that have been set or updated are included.

My custom fields did not have any value set, so CRM simply did not include them in entity.Attributes collection.

Upvotes: 1

Related Questions