Saturday, April 09, 2011

Microsoft Dynamics CRM 2011 JavaScript Development Cheat Sheet

Microsoft Dynamics CRM 2011 has dramatically changed the JavaScript programming experience when compared to CRM4. So I thought a cheat sheet (or a quick reference document) would help myself get familiar with the latest programming interface. You may download it from the following link on my Windows Live SkyDrive. (Also available at Google Site).


On a side note, some of you may have been curious about (or possibly somehow frustrated by) such API level changes made by MSCRM team in CRM v2011. I think the changes are made for good reasons.
  1. The first motivation is really about the industry standard of JavaScript development. In CRM 4, we use crmForm.all.xxx syntax everywhere, which is really convenient. But it is actually against the best practice in JavaScript development, as this technique is not supported by any other browsers. You may think that CRM2011 is only supported by IE at this moment anyway, why would I care about any other browsers. You are right, CRM2011 is not a cross-browser application, but it doesn't mean that is going to be the case forever. I am relatively confident that the next MSCRM will be a cross-browser one. In fact, I had a close look of some CRM 2011 JavaScript code the other day, I was under the impression that CRM team (probably part of the team) might have tried to make MSCRM 2011 a cross-browser one, but they didn't make the cut for some reasons.
  2. The new CRM 2011 library provides a lot more richer API than CRM4. So we shall require less hacking code if we can take full advantage of the new library, which makes our code more compatible with the future versions.
Note that this cheat sheet primarily focused on the development of CRM form scripts. It didn't cover all aspects of CRM client development practice. If you need a more comprehensive reference of CRM 2011 development practice, SDK document (Download Link) is the best resource available.

As a final note, you should quit using crmForm.all.xxx syntax in CRM 2011 if you are still doing so. ;-)

I hope the cheat sheet useful, and it worths a small spot on your cubicle wall(s). ;-)

[Update - Jun 6, 2011] I uploaded a new version with many fixes of the problems caused by copy/paste. I didn't realize the problems until last week, mainly because I don't work with CRM on day-to-day basis. Sorry for the inconvenience.

23 comments:

  1. This is fantastic! I'm so happy that you've taken to time to put this together so that I don't have to :)

    Many thanks, and yes - this will be printed and mounted to my workspace.

    Cheers, Craig

    ReplyDelete
  2. @Craig, you are very welcome! Thanks for letting me know that you like it.

    ReplyDelete
  3. beautiful. Excellent cheat sheet. That is exactly why you have had 50000 page views with useful blog posts like this one

    keep up the good work.

    I also not you are a fellow Java certified person, good work sir. There aren't many people in the CRM world who are Java certified.

    ReplyDelete
  4. Thanks crmbusiness! I just realized that I have misplaced the Applicable cells for getPrecision and getRequiredLevel methods of Xrm.Page.data.entity attribute. I just quickly updated the pdf file.

    ReplyDelete
  5. This is fantastic! I'm so happy that you've taken to time to put this together so that I don't have to.

    Logo design company

    ReplyDelete
  6. that was great, really helpful resource.

    thanks for sharing.

    ReplyDelete
    Replies
    1. Really amazing file...
      Thanks a lot to share this PDF file.

      Delete
  7. one stop reference for CRM 2011 Javascript Reference
    Good Work Daniel

    ReplyDelete
  8. Excellent cheat sheet Daniel! I highly recommend using this while developing CRM 2011 JavaScript.

    ReplyDelete
  9. Good one Daniel! Very helpful!

    ReplyDelete
  10. Thanks Vishal, Siva, Matthew, Pradeep...

    I have just uploaded a new version with some fixes of the problems caused by copy/paste in previous version. I found out copy/paste is my biggest enemy when it comes to the quality of my work, however, I don't seem to be able to find any other better way to be productive. ;-)

    ReplyDelete
  11. Hi Daniel,I got chance to read through some of your blogs today. I have to say, I learned lots from them. Great job!

    ReplyDelete
  12. Oh no ... I can't find the link to the PDF! Can you please help?

    ReplyDelete
  13. I just uploaded the same file to my Google site, hope this helps.

    Cheers,
    Daniel

    ReplyDelete
  14. Thanks for sharing - very useful :)

    ReplyDelete
  15. Hi Daniel,

    I have a problem with a js function, called from a custom ribbon button. This first function ("on_click") should call another function ("createRecord"), which is contained in a js webresource(uploaded in the solution). Although this resource is added to the form, when I click the button and the first function is fired, the "createRecord" from the js webresource is not found. I noticed that the first function is loaded in a so called scriptblock, and not displayed as it should in the js debugger (of IE9). I see the second js file loaded, with the proper name. What could be the problem ?

    ReplyDelete
  16. Hi Mihai, the problem that you have described is probably related to scoping issue. Try the following syntax to define your second function to see if it helps.

    window.createRecord = function (arg1, arg2) {
    };

    Also, you need to make sure that the second file has no syntax error.

    ReplyDelete
  17. Hi Daniel,

    Unfortunately, it didn't work that way. I had to add some lines in the first js file, that create the "script" tags on the fly, and reference the second js file inside those tags. Found this trick in a CRM4 programming book, not so elegant ...
    Thanks.

    ReplyDelete
  18. Do you know if the CRM record DELETE fires a javascript event?

    ReplyDelete
    Replies
    1. You would typically interact with DELETE event in CRM plugin. But if you would definitely need to hook up to DELETE event in the form, you may want to look into ribbon customization.

      Delete
  19. beautiful. Excellent cheat sheet. That is exactly why you have had 50000 page views with useful blog posts like this one

    keep up the good work.

    I also not you are a fellow Java certified person, good work sir. There aren't many people in the CRM world who are Java certified.




    -----------------------------
    cheap basketball shoes

    ReplyDelete
  20. Thanks Craig... Really appreciate your effort.

    ReplyDelete
  21. Yes, very nice! Thanks. I use it all the time. The links are key.

    ReplyDelete