Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)
Answered

java script debugging

Posted on by 167

how to debug a java script step by step

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: java script debugging

    Use Fiddler tool for step 3 .

    pastedimage1595254057994v1.png

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: java script debugging

    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.

    pastedimage1595253737626v1.png

    Thanks,
    Sumit

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: java script debugging

    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.

    debug2.png

    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 .

    debug2.png

    Step 5 : Go to function and click on the left pane to put break-point.

    debug3.png

    Step 5: trigger the JS from UI , it will automatic start debugging.

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: java script 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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans