Tuesday, February 4, 2014

Debugging CRM 2011 - Debugging JavaScript Files Loaded Asynchronously

I still use Internet Explorer 8 at times to mimic client environments.  I ran into an issue the other day where I needed to debug some onLoad JavaScript that I wrote on a form.  Since Roll Up 12 changed the loading of JavaScript web resources on forms from synchronous to asynchronous, you can't just edit a file directly in the IE debugger.  First, your JavaScript files aren't in the list of files to debug [my screenshots are on roll-up 15]:


The closest that you can get is in the FormScript.js file, where you can still see the functions that will be fired onLoad:



But if you do try to step into that function on IE8...


Now if you move to Internet Explorer 9 or higher, you can debug.  Remember that every time the form loads it re-loads your JS files, so you can't insert breakpoints as they'll just disappear.  For onChange events you can put breakpoints in your code after the files are loaded and for onLoad you can use the FormScript.js file as shown above.  You just have to go to the 'Other' listing and find out which file your code is in since they're not named like in Roll Up 11 and earlier:


In my case, it's script block 15:


I hope this helps!