Tricky Base64 Images in Dynamics reports/word templates

By | February 26, 2019

 

I think at least half of my posts should start with “I was pulling my hair out, and then..”

Image result for pulling my hair

(Like the picture? Here is the source)

If you ever tried creating a printer-ready screen in Dynamics that would, among other things, display a Base64 image stored in a field, you might know the feeling.

There are two possible options out of the box, it seems:

  • We can use an SSRS report
  • We can use a Word Template

However, here is what I was observing when trying to download a word template that would display my Base64 image:

image

And, in the SSRS, I was observing different things, but, in the end, no images would be displayed (I think I’ve also seen “Errors” in that column, but I could not reproduce those now):

image

Here is the thing, though. I was using a PowerApp to create those images through a Camera control, so, if you look at the screenshots above, you’ll notice how there is a prefix added to the Base64 string which identifies the type of that string: data:image/gif;base64

I did not know that was the problem – for that matter I did not even think twice about that part.

Until I ran (not even sure how – somewhat by luck) into this awesome thread on the community forums where Wouter Madou provided all the explanations needed to make this work:

https://community.dynamics.com/crm/f/117/t/234072

Short version – just remove that data:image/gif;base64 from the string. Picture content control in the templates does not seem to understand that prefix.

That took care of the Word templates, though I am still unable to display those images in the SSRS report. Well, I can actually display them in the Visual Studio when previewing the report, but not directly in Dynamics for some reason.

On the flip side, I also had a web resource on the form that would be displaying the same image in an iframe. That web resource was using the technique described here to display the image, and this is where the prefix is, actually, required (so, in other words, once I’ve removed the prefix, my web resource could not display the image anymore). That’s the lesser evil, though, since I can just add the prefix through javascript.

Well, that’s enough of hair pulling for now, and I can get back to wrapping up my PhotoID prototype – will be using a Word Template for ID printing.

Leave a Reply

Your email address will not be published.