Dynamics CRM: Writing and Debugging JavaScript
Posted Thursday, March 25th, 2010
One of the biggest complaints I hear about MS CRM is the is JavaScript editor, or the real lack thereof. For small easy JavaScripts I do write the JavaScripts in there, however, for bigger complex scripts I don’t. I always use Visual Studio. I create a Web Application project for the project I am on and then add new Jscript items to the application, one for each form and event. The reason I do this is because Visual Studio will alert my of any syntax errors. Plus if your Visual Studio is connected to a source control, now you have versioning of your scripts. When I am done writing the script I then copy and paste over to the MS CRM editor.
After I copy the script then I test it out. If it is not working and I need to debug I set up debugging in my browser and code. The following are the steps to do this.
- In my JavaScript I put “debugger;” in the line before I want the debugging to start.
- Go to Internet Explorer
- Click on Tools > Internet Options
- Go to the Advance Tab and uncheck the Disable Script Debugging. It is under the Browsing heading
Now run the application and when it gets to the debugger; line it should ask if you want to debug using Visual Studio. If you have multiple versions it will ask you which version. You can then step through the JavaScript and use the Immediate Window to look at variables.
Once I am done I always disable the debugging because you would be amazed at how many sights have JavaScript errors and the browser will ask you if you want to debug them.


