Friday, July 18, 2008

Debugging Javascript Code in MS CRM 4.0

Man... It was real tough not knowing how to debug Javascript Code in MS CRM 4.0. Every time I had to publish the forms and test with Alert Messages. It really got on my nerves and thought I better find a way out of this and that is when Stunnware helped me. I wanted to share the learning with you and here it is...


Open the Internet Explorer settings and select the Advanced tab. In the list of available options find the "Disable Script Debugging (Internet Explorer)" setting and make sure it's unchecked.


Open any script you want to debug and place the following just before the statement where you want to start your debugging session:
debugger

That's all, no semicolon, nothing else. To test it, run your form from the designer (preview mode) or publish it first. Once the script engine reaches the debugger statement, a list with all available debuggers is presented to you, including the Microsoft Script Debugger, Visual Studio 2003, Visual Studio 2005 or whatever is registered as a script debugger on your machine. You should try all debuggers to find the one you're most comfortable with and mark it as the default.

Like any other statement, you can simply comment out the debugger statement, so
//debugger
will actually turn off debugging.


All users that have not unchecked the "Disable debugging" setting in IE will not be prompted to start a debugger. However, you should make sure that you remove these statements before publishing them to a production environment. The easiest way to ensure it is to export all customizations and search the export xml file for "debugger".


For more information about the debugger statement, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/1e9b3876-3d38-4fd8-8596-1bbfe2330aa9.asp.



Happy Debugging Javascript Code in MS CRM 4.0 !!!

1 comment:

Unknown said...

WOW ! thanks !
There's nothing in life compared to proper debug conditions... I'd give my hand (just a way of speaking) if I could use a similar technique to debug my whole life ;-d