Printing Entity Images on Reports in Dynamics CRM 2013

By | December 26, 2013
In our earlier post Now Store Images in CRM 2013 we discussed at length about the new Image attribute added to CRM 2013. It included steps to programmatically read/write to this field. The next step being the ability to include the image attribute in the reports.

This seemingly appears a simple task to include images just as the images were picked up earlier from the notes entity and displayed on the report. But when we tried to do the same with the image attribute, we found that the image attribute is actually not stored the same way as the attachments. 

We could use the following code to read the image data using the CRM SDK.

string binaryImageQuery =
@”<fetch mapping=’logical’>
<entity name=’lead’>
<attribute name=’fullname’ />
<attribute name=’entityimage’ />
</entity>
</fetch>”;

EntityCollection binaryImageResults = _serviceProxy.RetrieveMultiple(new FetchExpression(binaryImageQuery));

This would return the image data in binary format that we could then read in a byte array.

But when you execute the same fetch query using BIDS for report designing, you receive the following results. 

This appears all good but when you set the control source of the image control on the form to the entityimage attribute, it returns an error about the data in the field not being in correct format.
Upon further review of the results we found that the System.Byte[] did not mean the binary data but only the string “System.Byte[]”.


The Fetch query when executed using the RetrieveMultipe API as shown above returns binary data. But when the same query is executed using the
ExecuteFetch API call, the results are returned in xml format and therefore the image attribute returns only a string “System.Byte[]” not the actual image binary data in Base64 string.

ExecuteFetchRequest fetch = new ExecuteFetchRequest();

fetch.FetchXml = binaryImageQuery;

_service.Execute(fetch);

As a result of this, reports designed using FetchXML (reports in CRM Online) would not be able to include images on the report.

On-Premise installs can still add the images in the report using SQL queries.

select con.FullName, con.Parentcustomeridname,con.entityimage  fromFilteredContact con

Bind the image control in the report to entityimage attribute

 

The result would be

Hope this helps anyone trying to include images on reports.