Home > Extensions > Web Resources > Scripts > CRM Common JScript File

I use a lot of the same function on multiple pages, and I think a lot of you do to. You can create a common JScript file and load it during an onload event, extending the functionality of your CRM. This is particularly useful because it reduces the amount of changes you have to make when you want to change how something works.

Code reuse is important, and I believe in creating libraries and using libraries. Javascript files are libraries, and they are cached. So if you update a Javascript file you are loading this way, make sure your users clear their cache.

function loadjs(filename, onload){
  var scriptfile=document.createElement('script');
  scriptfile.setAttribute("type","text/javascript");
  scriptfile.setAttribute("src", filename);
  scriptfile.onreadystatechange=onload;
  document.getElementsByTagName("head")[0].appendChild(scriptfile);
}

loadjs("/MoreJavascript/tools.js", function(){
	if (this.readyState == 'loaded' || this.readyState == 'complete') {
		FunctionInJavascriptFile();
		this.onreadystatechanged=null;
	}
});

CRM 2011 uses web-resources which can be a common JScript file.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 MSCRM Blogger

This site does not necessarily represent the views of Microsoft. The material posted on this blog are provided AS-IS, and you are to use the content at your own risk. Some of the code and information on this site may use unsupported methods. If you experience any problems using the information provided through this website, please post a comment and we will do our best to assist you, however, we can in no way guarantee support or resolution.

Microsoft Dynamics®, Silverlight®, Visual Studio®, and the corresponding logos are a registered trademarks owned by Microsoft Corporation. MSCRM Blogger has made every effort to supply trademark information about company names, products, and services mentioned on this blog. All third party trademarks are the property of their respective owners. Any rights not expressly granted herein are reserved.