CRM 4 – Debugging Javascript

I was trying to debug some javascript today in CRM 4.  I initially tried to use the brilliant F12 internet explorer (8 plus) web development tool.

A wierd thing happens in CRM 4 compared to CRM 2011.  In CRM 2011 because it is a web resource, it’s that file which is loaded.  This makes it easy to look at the list of scripts and then pick the one you want to debug.

but with CRM 4 it is different because it is a file called FormScript.js with lots of variables after it’s name.  The other frustrating thing is it doesn’t have your onLoad script in it straight away, it adds it later on.  This means you can’t put breakpoints on your code because it isn’t loaded yet.

The thing that really annoyed me was it kept creating a new Javascript file everytime I ran it.  Then once it was loaded and you put a breakpoint in the js file it created a new one.

In the end I did manage to put a breakpoint on the original FormScript.js and then one hit the breakpoint it had loaded my script and I could place some breakpoints in my code.  The only problem is I’m not totally sure I could do it again.

I also tried the debugger method.  This is basically adding the word debugger to your javascript code and then when it hits this, it asks you where you want to debug the code.  You can then choose Visual Studio and step through your code.

The only problem I had with this method is I couldn’t add breakpoints and the javascript I was trying to debug was creating functions and callbacks.  This is why it’s good to do it Internet explorer debugger because you can put breakpoints anywhere.

You should check out this blog post – Tips for productive Javascript in CRM dynamics 4.  It has a few good tips, the tip below shows you the settings you need to debug the javascript in visual studio, there is an internet explorer setting you need to adjust


Use the debugger statement in your code if you want to walk through code.  You are able to leverage Visual Studio to analyze variable values as you execute your code.  Very useful!

First, within Internet Explorer, uncheck “Disable script debugging  (Internet Explorer)” and “Disable script debugger (Other)”

Next, add following code before any code you would like to debug.



One thought on “CRM 4 – Debugging Javascript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.