Answered by:
Debugging errors - best practice?

Question
-
I keep reading how hard CRM and javascript are to debug, so I was wondering how the community would handle debugging the scenario where a form throws an error:
There was an error with this field's customized event.
Field:window
Event:onload
Error:Access is denied.
How do I capture what has been denied? How do I get more data about what's wrong than the ever-so-helpful pop-up error message?Wednesday, October 14, 2009 9:10 PM
Answers
-
Hi,
Well, I hope Microsoft can provide a better way of debug JavaScript in the future. Currently, if you don't have any coding experience, you need to comment out your JavaScript code line by line to figure out what is wrong.
If you are familiar with coding, what you can do is to write a few lines of code to call a custom js file resides under a same website. In your custom js file, place your JavaScript code in there. This way, you CRM form will always call the js file on the onLoad event. You can comment out your code in the custom js line by line to see what was wrong. Also you don't have to keep going to the CRM form editor and keep publishing the entity to see the changes.
Another way is to enable your browser for debugging, put the "debug;" syntax in your code. Then following instruction to step through your code.
Here's more information for you to debug your JavaScript.
http://www.jarrodgoddard.com/web-development/internet-explorer-7-javascript-debugging
I hope this makes sense to you.
Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com- Marked as answer by Elytron Thursday, October 15, 2009 3:20 PM
Wednesday, October 14, 2009 11:25 PMModerator
All replies
-
Hi,
Well, I hope Microsoft can provide a better way of debug JavaScript in the future. Currently, if you don't have any coding experience, you need to comment out your JavaScript code line by line to figure out what is wrong.
If you are familiar with coding, what you can do is to write a few lines of code to call a custom js file resides under a same website. In your custom js file, place your JavaScript code in there. This way, you CRM form will always call the js file on the onLoad event. You can comment out your code in the custom js line by line to see what was wrong. Also you don't have to keep going to the CRM form editor and keep publishing the entity to see the changes.
Another way is to enable your browser for debugging, put the "debug;" syntax in your code. Then following instruction to step through your code.
Here's more information for you to debug your JavaScript.
http://www.jarrodgoddard.com/web-development/internet-explorer-7-javascript-debugging
I hope this makes sense to you.
Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com- Marked as answer by Elytron Thursday, October 15, 2009 3:20 PM
Wednesday, October 14, 2009 11:25 PMModerator -
You can use Visual Studio to debug client-side JavaScript. If you want to debug in IE Browser You need to first enable script debugging in your browser:
- In Internet Explorer, click the Tools menu and choose Internet Options.
- Click the Advanced tab.
- Under the Browsing category, clear the Disable Script Debugging checkbox.
Put the following in the Onload Event as starting line.
debugger;
Try to open the form in the Create Mode or Update Mode and it would ask you if you want to debug the code. Select one of the Editors it gives you to debug. Now you can see the cursor pointing at that debugger; line.
You can also publish the form and try opening it from the web interface still you need to follow the same procedure to debug. Some times you got to debug after publishing because there are certain cases that are not valid in create or update mode. For example if you are writing code to hide one of the left nav bar links- Proposed as answer by Santosh Kore Thursday, October 15, 2009 1:18 AM
Thursday, October 15, 2009 1:16 AM