JavaScript Libraries in Microsoft Dynamics CRM 2011
In Microsoft Dynamics CRM 4, it is a very tedious task for system customizers to manage and track JavaScript. System Customizers/Developers have to write JavaScript on every event handler on the form. But Microsoft Dynamics CRM 2011 provides JavaScript libraries that can be utilized on events and forms across the solution. Now common JavaScript functions can be written at one centralized JavaScript file and utilized across solution.
Moreover, multiple JavaScript libraries can be created. For example, one common library for general CRM Service calls and one common library for UI manipulation and so on.
Let’s create a very simple JavaScript library and create a function to hide/show a tab/section on the form. JavaScript libraries are added as web resources in solution as shown below:
Now let’s create a JavaScript Common Library by adding a web resource in the solution. Then attach a JavaScript file this web resource.
Now let’s open the file in Text Editor available in web resource to add a function to show/hide a section/tab on form.
Microsoft Dynamics CRM 2011 provides new xrmPage model to access UI and data at client side. Here is a snapshot of the hierarchy.
Now let’s go to the account form in solution and then go to form properties to set JavaScript library and function to execute on form load event handler as shown below:
Now let’s add library from solution library.
Now let’s call the HideShowSection function in JavaScript Library by selecting appropriate JS library and typing the right function. Enable the event handler by setting Enable flag to true. Also pass parameter to function by comma separated list of parameters i.e. 1, false which in turn sets tab 1 to visible false.
You can see that Details tab is now hidden and alert.









Fantastic post, Ayaz. I posted a link to it on the CEI blog:
http://blog.customereffective.com/blog/2010/09/a-closer-look-at-crm-2011-jscript-libraries.html
Thanks Joel, Appreciated!
I’ve been waiting for a CRM 2011 JS Library post, I was going to do one myself, but it looks like you’ve taken care of it. Thanks for the good post; we should link share sometime.
-Paul Reitmeyer
Very good blog dude..
Hi Ayaz, I’ve heard that each JavaScript Common Library web resource can only contain a single function. Is that true?
Hi Ayaz,
Iam using crm 2011. On form load of an entity ” object doesnot support this property” error is coming.
I haven’t written any javascripst and nor attached websresoures.
Need help.
Thank you
I have a web resource which is a HTML page, on clicking a button on the html page I would like to assign a value to text box control on the parent CRM 2011 form. Could you please advise?
You can setup CRM v4 to more efficiently share Javascript across entities, it just takes a bit more planning, thinking and design. You are correct that CRM v2011 makes bundling much more efficient and slick!
You are right Anne but when it comes to outlook and outlook offline clients then managing those JavaScript libraries will be nightmare.
This blog appears to recieve a large ammount of visitors. How can you obtain traffic to this? It gives a nice individual twist upon issues. I guess getting something authentic or substantial to give info on is an essential factor.
Hello would you mind sharing which blog platform you’re working with? I’m going to start my own blog in the near future but I’m having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!
I love Big Time Rush! I cannot wait to see them in Concert!
Ayaz. Can you provide a code sample for hiding/showing sections based on values in an optionset/picklist?
Ayaz, i’m trying to do a library that contains all the common functions that i use to customize, but i’m not able to call a function put on “Library A” from “Library B”. Do you know if that is posible?
Hi, i’ve 2 forms in an entity, and i want the system to auto change to certain form on the first time it load based on field’s value. I’ve tried Xrm.Page.ui.formSelector.items.get(1).navigate(); , but the ribbon will be disabled after it load to another form. Any idea?
How can i call a function from the same library with different parameter more than once. Because when i do so only one of them works
Hi Ayaz,
I need help.
in my case, I must enter the “field of due date”.
e.g. a case with product A, to be completed during 2 working days.
let say case created on Friday, 25 Nov 2011 (03:00 AM), the due date = 2 days of work.
means the due date shall be automatically filled = Tue, 29 Nov 2011 (03:00 PM).
My question is:
- Whether the above can be done by mscrm workflow feature? (if yes, how…? ^.^). or
- Whether the jscript can perform the calculation of due date. with validation work hours and holidays? (if yes, how…? ^.^).
please advice and help …
Thank you in advance.
de Sandoz