Thursday, September 30, 2010

'Automation server can't create object' JavaScript Error


Occasionally I run into a user that gets the Automation server can't create object error message. This is typically caused by a method in JavaScript that attempts to create an ActiveXObject for something like evaluating XML or creating a GUID by using the Scriptlet.TypeLib ActiveX object. To address this issue you need to go to

Internet Explorer Tools > Internet Options > Security > Local Intranet

and hit the ‘Custom level...’ button (IMAGE 1).  This will cause the 'Security Settings - Local Intranet Zone' (IMAGE 2) to display.  From this form you need to scroll down to the 'ActiveX controls and plug-ins' section and then enable the

Initialize and script ActiveX controls not marked as safe for scripting

and then click the OK button on the form.  Then click the Apply button on the Internet Options form and restart Internet Explorer to have the changes take effect.  Most times this will address this issue and allow the JavaScript on the form to work.



IMAGE 1


IMAGE 2

Thursday, September 16, 2010

Bit field events

Are you struggling to get the onchange event to fire on a checkbox or radio button? Are you clearing your cache and refreshing your page and seeing no results? Well just the other day one of the other members on my team was having this issue and he came to me for some help. He had something like this
crmForm.all.new_bit.onchange = function() {
  alert(“I changed”);
};

and could not understand why he was not getting the alert when he clicked on the radio buttons for the bit field.

It only took me a second to see what was happening. First the onchange event will not fire until the radio button group looses focus or the blur() event is called on the radio button. After explaining this to my teammate I got the next logical question of, “Well how do you make the event fire when the user clicks on the radio button?” This was an easy one to answer, I said, “Replace onchange with onclick.” So he changed his to code to look like this
crmForm.all.new_bit.onclick = function() {
  alert(“I changed”);
};

So to recap for a checkbox or radio button
  1. onchange does not fire until radio button looses focus or blur() is called
  2. Use onclick if you want an event to fire as soon as a radio button is clicked.

Sunday, September 5, 2010

Load External JavaScript a.k.a. Dynamic JavaScript

The script below will dynamically load a JavaScript script file to a form in MSCRM 4.0 and is functioning as of RollUp 11.  You will need to add this to the onload event of the form and ensure that you have checked the checkbox for enable onload event.  Please note that this is not supported by Microsoft and may not function if you apply a future release of MSCRM or any rollup after Rollup 11 for MSCRM 4.0

//Create a variable to hold the path to the file you want to load.  In this case I am loading my Global.js file which contains a number of functions that I use on a number of my pages
var url = '/ISV/Global.js';

//Create the ActiveX object which will load the *.js file
var x = new ActiveXObject("Msxml2.XMLHTTP"); 

//Get the file and eval it
x.open('GET', url, false); x.send('');
eval(x.responseText); 

//Break the file done by line breaks
var s = x.responseText.split(/\n/); 

//Regular expression
var r = /^function\s*([a-z_]+)/i; 

//Eval each line of the returned file.  Once this is done the loaded *.js file will be available
for (var i = 0; i < s.length; i++) 
{ 
  var m = r.exec(s[i]); 
  if (m != null) {
    window[m[1]] = eval(m[1]); 
  }
}