0

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!

Ivan Jovović
  • 5,238
  • 3
  • 29
  • 57
  • what means "CRM plugin can not find this or any other custom field", do you mean that if you do `entity["firstname"] = "TEST";` with `firstname` as standard field, your retrieve returns the updated value? – Guido Preite Jun 06 '14 at 10:57

2 Answers2

1

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.

Community
  • 1
  • 1
Ivan Jovović
  • 5,238
  • 3
  • 29
  • 57
  • please mark your answer as the correct one, will help other users to find it as relevant. – Guido Preite Jun 06 '14 at 12:39
  • @GuidoPreite: Thanks, I will, but I have to wait for 48 hours to accept my own answer: http://blog.stackoverflow.com/2009/01/accept-your-own-answers/ – Ivan Jovović Jun 06 '14 at 13:00
  • Thank you for this answer. I just added a value in one atteribute for one Account and then this atteribute was present in my collection. It makes a bit sense to not include atteributes with no values, but on the other hand it could potensially be a pain to figure out. – Hallgeir Engen Feb 06 '15 at 10:09
1

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.

Zeeshan Ahmed
  • 173
  • 3
  • 11