Showing an attached image on a CRM form (pure javascript) IE8+ only

Update: September 2012
I had to use this code again and found some users were receiving “Access Denied” errors – as reported in comments to this post. Looks like this is due to a bug in certain versions of IE.

The fix is available here… http://support.microsoft.com/kb/2601307/en-us?sd=rss&spid=15672

Had a requirement to show an image that has been attached through the notes system on a CRM form. Here’s how it’s done:-

To retrieve the image data, I use Daniel Cai’s excellent CRM Web Service Toolkit which still works beautifully in CRM 2011. A simple fetchXML query to retrieve the documentbody from the annotation entity against the related objectid is all it takes.

IE8 onwards appears to support display of inline images under various encoding methods (including Base 64). The syntax is:-

</pre>
<img src="data:image/jpg;base64,IMAGEDATA" alt="" />
<pre>

So here’s the finished JavaScript:-

function form_onload() {

  var id = Xrm.Page.data.entity.getId();

  var fetchXml = [
  "",
    "",
      "",
      "",
      "",
      "",
        "",
        "",
        "",
      "",
    "",
  ""].join("");

  var fetchData = CrmServiceToolkit.Fetch(fetchXml);
  if (fetchData.length == 0) { return; }

  var img = fetchData[0].getValue('documentbody');

  var el = document.getElementById("IFRAME_image");
  if (!el) { return; }

  img = "</pre>
<img src="\&quot;data:image/jpg;base64,&quot;" alt="" />
<pre>";
  el.contentWindow.document.body.innerHTML = img;

}

Hope that helps someone out!

Leave a comment

46 Comments

  1. HI
    Thanks for your sharing! Very good

    Sometimes it works and sometimes not: same record and same image sometimes it shows and sometimes not! it appears “error 404 Resource not found”

    I think the problems is time to load the image , howver the size is nera 40k.

    How can I avoid the error message?

    Regards
    Helena

    Reply
    • Helena,

      That’s a weird problem.

      You could try switching the query to run asynchronously…


      var fetchData;

      function form_onload() {
      var id = ...;
      var fetchXml = ...;
      fetchData = CrmServiceToolkit.Fetch(fetchXml, fetchCallBack);
      }

      function fetchCallBack(fetchData) {
      if (fetchData.length == 0) { alert ("No image data received"); }
      var img = fetchData[0].getValue('documentbody');
      var el = document.getElementById("IFRAME_image");
      if (!el) { alert("Iframe not found"); }
      img = "";
      el.contentWindow.document.body.innerHTML = img;
      }

      (Code untested).

      Let me know if that makes it work any better.

      Reply
  2. Robert

     /  May 25, 2012

    Onload event generates “Error:Access is denied” even though I have System Admin role.

    Reply
  3. Hey there! I know this is somewhat off topic but I was wondering which blog platform are you using for this website?

    I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be fantastic if you could point me in the direction of a good platform.

    Reply
  4. Fine way of explaining, and nice article to take information
    concerning my presentation subject matter, which i am going to present in college.

    Reply
  5. Heya this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you
    have to manually code with HTML. I’m starting a blog soon but have no coding know-how so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!

    Reply
  6. It’s wonderful that you are getting ideas from this piece of writing as well as from our argument made at this place.

    Reply
  7. Si vous appréciez marches ou balades à vélo,
    vous pourrez parcourir le réseau de chemins de randonnées ou de petites routes peu passantes, au départ de la
    maison. Vous pourrez en une heure ou deux à pied accéder
    à la grotte des huguenots, une tombe antique creusée dans
    la pierre, l’Eglise, la tour de guet avec sa vue à 360°,
    ou encore le volcan de Chirouze. Nous tenons à votre disposition les cartes et guides
    de la région et pourrons vous conseiller en fonction de vos désirs.

    Pour découvrir la région en voiture, vous vous rendrez à Privas en 15
    minutes, Aubenas en 30 minutes, Antraigues en 45
    minutes, Vallon Pont d’Arc en 1 heure, Le Mont
    Gerbier de Jonc en 1 heure et 15 minutes. Pour les gourmands de produits du terroir
    vous trouverez à Privas : marrons glacés Clément Faugier,
    charcuterie (caillettes, jambons, saucissons séchés en montagne), fromages de chèvres (les fameux
    picodons), côtes du Rhône rouges ( Syrah, Merlot, …), et blancs (Chardonnay,
    Viognier, …)

    Reply
  8. My family all the time say that I am killing my time here at net,
    but I know I am getting experience every day by reading
    thes fastidious articles.

    Reply
  9. Thanks to my father who told me concerning this web site,
    this web site is in fact awesome.

    Reply
  10. Hello friends, its impressive paragraph about tutoringand fully explained, keep it up all the time.

    Reply
  11. Hey There. I found your blog using msn. This is a very well
    written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I will certainly comeback.

    Reply
  12. I’ve been exploring for a little for any high quality articles or blog posts in this sort of house . Exploring in Yahoo I finally stumbled upon this site. Studying this info So i’m happy to
    convey that I have an incredibly good uncanny feeling I
    found out exactly what I needed. I such a lot undoubtedly will make certain to don?
    t forget this web site and give it a glance regularly.

    Reply
  13. You need to check as many paphos car hire associations as possible for the holiday-lovers to migrate from
    one place to another clearly an area with less Verizon juice.

    Reply
  14. After I originally commented I appear to have clicked
    on the -Notify me when new comments are added- checkbox and now every time a comment is added I get four emails with the
    same comment. Perhaps there is a means you are able to
    remove me from that service? Thanks!

    Reply
  15. I appeciate this discussion here on Showing an attached image on
    a CRM form (pure javascript) IE8+ only | Pete’s CRM 2011 Stuff. We are in OC|an Orange County realty.

    Reply
  16. In need of an earpiece for work and came across this site,
    it really is so confusing, all i know is that i would like a sepura
    earpiece, your article post has helped but i need to
    investigate somewhat more!

    Reply
  17. I was recommended this web site by my cousin. I am not certain whether or not this submit is written by means of him as
    no one else recognise such distinctive approximately my difficulty.
    You’re incredible! Thanks!

    Reply
  18. Aw, this was a very good post. Taking the time and actual effort to make a very good article… but
    what can I say… I put things off a lot and never seem to get
    nearly anything done.

    Reply
  19. Thankfulness to my father who stated to me regarding this web site,
    this webpage is truly remarkable.

    Reply
  20. Hi, just wanted to mention, I liked this article.
    It was practical. Keep on posting!

    Reply
  21. I usually do not respond to messages, but on this case. WoW!

    Reply
  22. May I simply say what a comfort to discover an individual who genuinely understands what they are discussing on the web.

    You certainly realize how to bring a problem to light and
    make it important. A lot more people really need to
    check this out and understand this side of the
    story. I can’t believe you are not more popular given that you certainly have the gift.

    Reply
  23. Hey There. I found your blog using msn. This is an extremely well
    written article. I’ll make sure to bookmark it and return to read more of your useful information. Thanks for the post. I will certainly return.

    Reply
  24. To tak naprawdę perfekcyjny oraz pomocny kawałek wiadomości.
    Jestem szczęśliwa, że trafiłam na Twój materiał. Dzięki za udostępnienie.

    Reply
  25. Shoppers can save up to 70 mph. Positive effects of farmacia on line;
    70 to 85 percent of men, these two markets alone could make PT-141 a pharmaceutical blockbuster.
    Well, still very recognizably” Motorola” about the fungus harvest, said in a press release Tuesday.

    Reply
  26. Heya i am for the primary time here. I came across this board and
    I to find It truly useful & it helped me out a
    lot. I hope to provide something back and aid others such as you aided me.

    Reply
  27. I hardly write comments, but i did a few searching and wound up here
    Showing an attached image on a CRM form (pure javascript) IE8+ only
    | Pete’s CRM 2011 Stuff. And I actually do have a few questions for you if you usually do not mind. Is it only me or does it seem like a few of these remarks look like they are written by brain dead individuals? 😛 And, if you are posting on additional social sites, I’d like to keep up with anything new you
    have to post. Would you make a list of the complete
    urls of all your communal pages like your linkedin profile, Facebook page or twitter feed?

    Reply
  28. Hey there are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started and set up my own.
    Do you need any coding expertise to make your own blog? Any help would be really appreciated!

    Reply
  29. Woah! I’m really digging the template/theme of this website. It’s simple, yet effective.
    A lot of times it’s very hard to get that “perfect balance” between usability and visual appeal. I must say that you’ve done a excellent job with this.
    Additionally, the blog loads very quick for me on Safari.

    Exceptional Blog!

    Reply
  30. I like the helpful information you supply on your articles.
    I’ll bookmark your weblog and test once more right here regularly. I’m reasonably certain I’ll be informed lots of new stuff proper right here! Best of luck for the next!

    Reply
  31. I’m curious to find out what blog platform you’re using?
    I’m experiencing some minor security issues with my latest website and I would like to find something more risk-free. Do you have any recommendations?

    Reply
  32. Greetings from Florida! I’m bored to death at work so I decided to check out your blog on my iphone during lunch break. I love the knowledge you provide here and can’t wait
    to take a look when I get home. I’m amazed at how fast your blog loaded on my phone .. I’m not even using WIFI, just 3G .
    . Anyhow, wonderful blog!

    Reply
  33. Take Satisfaction In Your Cat By Following These Sturdy Suggestions.

    Cats are wonderful property creatures. If you’ll hold the opportunity to’t
    be as aspect of your respective property all time of evening, cats can dwell on
    their very individual. The next details will support you to
    discover all about cats.

    Within the celebration the holiday season rolls all roughly, safeguard
    your Xmas tree from curious kitties. It might see that tree and climb it.
    That could be an big difficulty. Will certainly not permit your dog dog to prowl all-round your tree.
    It’s possible you’ll have to also be certain that
    you are able to arrive throughout no loose garlands, ornaments or tinsel that is feasible for being eaten using the cat.

    Really actually will not have your cat carry a med if they’re not suffering out of one’s wellbeing concern it totally was designed to treat.
    Numerous of individuals flea medications you fit on your cat also cope
    with for parasites, mites and also other illnesses that your cat will not have and can not contract.

    Though these medications are prosperous on highway cats, they might be seriously not vital for
    indoor cats.

    The location with all the litter field is important.
    Your extremely 1st

    Reply
  34. My partner and I stumbled over here by a different website and thought I should check things
    out. I like what I see so now i am following you. Look forward to checking out your web page yet again.

    Reply
  35. Hello there, I discovered your site by means of Google even as looking for a related matter,
    your site got here up, it appears to be like good.
    I have bookmarked it in my google bookmarks.
    Hello there, simply became aware of your weblog through Google, and located that it is really informative.
    I am gonna be careful for brussels. I will appreciate when you proceed this
    in future. Many other people shall be benefited out of your writing.
    Cheers!

    Reply
  36. In many cases, the amount of place that you are purchasing the
    childrens beds for play and make clear it is an area for sleep,
    not amusement. At MOM’S safety comes first, so all of our childrens beds are strongly constructed and rigorously tested in independent labs to meet or exceed both ASTM and CSPC safety standards. This prevents any kind of risks.

    Reply
  37. I all the time used to read paragraph in news papers but now as I am a
    user of web so from now I am using net for articles or reviews, thanks to web.

    Reply
  38. Dentist is the most difficult to deal with childrens beds operate
    done at a private clinic. There are basically three ways of getting free childrens beds.
    Smoking is very bad for all aspects of root canal therapy including routine as well as being
    certified by the International Congress of Oral Implantology as well
    as practice management and community outreach. 99% bacteria
    that 01% is an elusive bugger, preventing cavities, and bad breath.

    Reply
  39. Hello my family member! I want to say that this post is awesome, great written and
    include approximately all significant infos.
    I would like to look more posts like this .

    Reply
  40. You could definitely see your expertise in the article you write.
    The sector hopes for even more passionate writers such as
    you who are not afraid to mention how they believe.
    At all times go after your heart.

    Reply
  41. It’s truly very difficult in this full of activity life to listen news on Television, so I only use world wide web for that reason, and get the newest information.

    Reply
  42. I’m curious to find out what blog platform you are utilizing?
    I’m experiencing some small security problems
    with my latest blog and I’d like to find something more
    safe. Do you have any suggestions?

    Reply
  43. I’m very pleased to find this site. I want to to thank you for
    ones time for this fantastic read!! I definitely liked
    every bit of it and I have you saved to fav to check out new things on your web site.

    Reply
  44. エッチの際に発射のが早い人を早漏といいます。しかし早漏でなければ男優は務まらないといわれるほどなので、じつは早漏自体は悪ではありません。大切なのは発射を操れるようになることです。必要とあらば1分以内に発射することもできるし、長くエッチを楽しみたいときは1時間でも挿入していられる。そのように訓練していくことが大切です。早漏には自律神経が関係していて、発射の指示を出すのは交感神経です。日頃の姿勢などによって自律神経を意図的にコントロールすることも不可能ではありません。遅漏など男性器4大トラブルの改善に役立つ方法をご紹介します。

    Reply
  45. However, he was still busy with a movie that was in the
    middle of production at the time the first pilot was to be shot.

    Reply

Leave a reply to Roseanne Cancel reply