Sunday, September 7, 2008

Reference External Javascript file in CRM form events

Some times you may have a great deal of Javascript code to insert into your CRM entity's form events, be it OnLoad, OnSave or OnChange of a control.

It is possible to encapsulate the functionality or procedures into separate JS files and reference them from the form. I often do this and have a list of standard JS files with specific functions as I need them. You can insert the file into your event by ading this block of code.

//Insert JS Functions to perform whatever functionality:

var script = document.createElement("script");

script.language = "javascript";

script.src = "http://crmserver:5555/ISV/JSFiles/CRMControlFunctions.js";

document.getElementsByTagName("head")[0].appendChild(script);


Don't forget to substitute your own server, port and filename. Ensure that it's hosted in a website or virtual directory and reachable from the CRMWeb website application.


No comments: