The CRM Grid – A Microsoft CRM Blog

Greg Owens’ rose-tinted MS-CRM mumblings

onLoad code not running

Another strange problem encountered and fixed today. The form onLoad code “suddenly” stopped working. I say “suddenly” because in fact this was a red herring and the problem turned out to be the result of a change. The symptoms were however unexpected.

Normally when a scripting error occurs in MSCRM, Internet Explorer will throw a script error dialog as the form loads (e.g. “There was an error with this field’s customized event.”):

scripterror

There was an error with this field's customized event

  Or alternatively a warning is shown at the bottom left of the Internet Explorer screen:

Error on page

Error on page

But on this occasion, there were no warnings. My first thought was to place a debugger statement into the code, but even after publishing this too failed to execute. I tried a simple alert() statement but this also failed. Odd.

Replacing all the code in the event handler with a simple alert() statement did work, so clearly this was a syntax problem, but very odd that it didn’t throw any error and in fact even blocked the debugger statement. If I were to delve deeper I’m sure I’d find that this is due to try…catch handling within the MSCRM ASPX pages…

In the end, the problem was caused by an htmlEncoded chevron character which had somehow been pasted into the javascript code (< ) while setting up a for loop.

Thanks due to Douglas Croxford’s JsLint for speeding the time to resolution somewhat.

6 Comments»

  Rahul wrote @

in my case the JavaScript in onload event stopped working suddenly , and now the simple alert() statement is not working also.
does anyone know how to get it working again.

  Greg Owens wrote @

A few things to ask before trying to answer your question:

Is the event enabled via the checkbox at the top of the screen in the event handler dialog box?
Is there any other code in the onLoad event for your form?
Have you published your changes for that entity?
Does it affect all entities or just one entity?
Have you modified any of the MSCRM files (e.g. global.js)?
Does the problem occur on just your own machine or on all client machines? (aka is it an Internet Explorer setting?

Best wishes

Greg

  Greg Owens wrote @

Here’s Rahul’s reply (he was marked as spam for some reason):

Hi Greg,
the event is enabled using the check box.
the JavaScript i had written was working until some days back.but now it isn’t.
a simple alert(’try’) statement isn’t working as well.
the JavaScript is firing properly in other entities.
No , i haven’t touched any of the MS CRM files either.
well it isn’t firing on any of the machine, I wonder whether it is related to any of the IE settings?
But I am still stuck in it.

Thanks for the reply.

Regards,
Rahul Lohar

  Rahul wrote @

Hey Greg,
I got it solved , i think the problem was that the code in onload event was alright, but the code in onSave event was missing a semicolon , which i think was creating the problem ,
But the weird thing i noticed is that it was never throwing an error when i saved the form.
But anyways i got it working again,

Thanks..

  Greg Owens wrote @

Great news Rahul and thanks for posting back with the update – hopefully this will help others with similar problems in the future 🙂

  Carolina wrote @

Thanks a lot for your post. I had the same problem and spent 2 days trying to solve. Thanks to your post I disabled all my form scripts and found that and error in an onchange() was causing all the mess.
Thanks!!


Leave a reply to Carolina Cancel reply