Tip #636: Use all attributes and miss some of the data

Entity imageLaziness is the engine of the progress. If it was not for Josephine Cochrane trying to avoid the house duties, we’d still be doing dishes by hand.

So we all guilty from time to time using all attributes when retrieving information from CRM. The consequences are not only spießrutenlaufen and eternal condemnation, but also dreadful performance and, as it turns out, missing information.

We learned from system job views, “all” does not always mean “all” in Dynamics CRM. It’s also true for fetchxml.

CRM will not return binary columns when all attributes are requested

That applies to entityimage attribute; the following fetchxml:

<fetch>
  <entity name="contact" >
    <all-attributes/>
    <filter>
      <condition attribute="firstname" 
	    operator="eq" value="Bruce" />
    </filter>
  </entity>
</fetch>

will not return the image itself.

This fetch, on the other hand, will:

<fetch>
  <entity name="contact" >
    <attribute name="entityimage" />
    <filter>
      <condition attribute="firstname" 
	    operator="eq" value="Bruce" />
    </filter>
  </entity>
</fetch>

Note that to retrieve image data using fetch you have to use RetrieveMultipleRequest instead of the deprecated ExecuteFetchRequest class. Latter will not return the image, whether you specify it or not.

3 thoughts on “Tip #636: Use all attributes and miss some of the data

  1. Kaveesh says:

    Entityimage which you have used is the logical name of the field or do we need to use it as it is “entityimage”.

    What if we have two image fields in custom entity and none of them is primary image but I need to retrieve data from both image fields?

    • At the time of writing it was called entityimage. Now you should use logical name. I believe specifying individual fields will work but I would strongly advise against using fetchxml for images, use Web API instead.

Leave a Reply

Your email address will not be published.