how to debug a java script step by step
*This post is locked for comments
how to debug a java script step by step
*This post is locked for comments
Use Fiddler tool for step 3 .
Hello Gautam,
Thanks for the detailed steps. I used to use both these approaches till last year. Now i use below listed approach to debug code very easily.
Advantage : No need to deploy the latest modifications in CRM instance and publish it while developing.
Steps:
1. Install Node.Js and Fiddler tool. Open up both the tools.
2. Using command prompt execute below listed commands:
a) npm i --global http-server
b) Navigate to the local folder location where your modified file is located.
cd C:\Sample_GIT_Solutions\CRMSolutions\Development\CRM.WebResources\Scripts
c) http-server -p 8080 -c-1
3. Add additional Rules to divert the traffic/required js file to use local file. (Rule -> Customize Rules) Use OnBeforeRequest method.
Like Below:
if (
oSession.url.Contains("sample.code")
|| oSession.url.Contains("finc")
|| oSession.url.Contains("sample.com")
) {
// show
} else {
// hide
oSession["ui-hide"] = "yup";
}
if (oSession.HostnameIs("sample-dev.crm.dynamics.com") && oSession.uriContains("sam_Lead.js")) {
oSession.fullUrl = "">localhost:8080/ltf_Lead.js";
oSession["ui-color"] = "green";
}
4. Open up required browser and press F12 to open Dev Tools.
5. Fiddler will force the instance to use local code and you can start debugging your local code.
Thanks,
Sumit
Hi ,
Simply write debugger; in your function before which code you are trying to debug.
Step 1. Write debugger beginning of function name .
function OnloadForm()
{
debugger;
}
Step 2: Make sure for internet explorer you have enable script debugging by removing check box going to browser settings -->internet options --> Advance and unchecked below options.
Step 3: Open Dynamics CRM and press F12 , it will open debugger window.
Step 4: Open the Dynamics CRM page where your JS registered .
Step 5: trigger the JS from UI , it will automatic start debugging.
You can also debug without writing debugger; when you open any page you can see all the JS ,HTML in the browser , here is the steps to debug without writing debugger.
Step 1: Open the forms where JS registered.
Step 2: Make sure you have enable debugger for browser mentioned above.
Step 3: Press F12 in keyboard , it will open debugger window ,
Step 4: Go to debugger Tab. and Click on Folder icon in the left. Under main.aspx you will find the JS file which you registered. Or you can search your JS webresource name .
Step 5 : Go to function and click on the left pane to put break-point.
Step 5: trigger the JS from UI , it will automatic start debugging.
Hi,
1. Open your web resource, use debugger keyword in your js function which you want to debug.
2. Save and publish your changes.
3. Open your entity form, press F12 if you are using IE or use Developers tools if using chrome
4. Initiate your event which is calling your js, it will go in debug mode.
You can also refer: blogs.msdn.microsoft.com/.../debugging-custom-javascript-code-in-crm-using-browser-developer-tools
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156