Wednesday, December 16, 2009

Load an external script file on the load of an entity.

Put the below code on a JS file and save it as “JoeTestScript.js” in the ("/ISV/CHALLITS/CRMExtended/Scripts/ folder.
// JScript source code
function TestScriptMethod()
{
alert(" Hi Joe you have called the external java script file");
}

function load_script (url)
{
var x = new ActiveXObject("Msxml2.XMLHTTP");
x.open('GET', url, false);
x.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
x.send('');
eval(x.responseText);
var s = x.responseText.split(/\n/);
var r = /^function\s*([a-z_]+)/i;
for (var i = 0; i < s.length; i++)
{
var m = r.exec(s[i]);
if (m != null)
window[m[1]] = eval(m[1]);
}
}

function add_script (url , load)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');

script.language = 'javascript';
script.type = 'text/javascript';
script.src = url;

if (load)
{
script.onreadystatechange = function()
{
crmOnLoadScripts();
}
}
head.appendChild(script);
}

add_script("/ISV//Scripts/opportunityproduct.js", false);
//ON SAVE
TestScriptMethod (); // please note that you have to call this on save

NOTE : Delete temporary internet files.

No comments:

Post a Comment