web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)
Answered

java script debugging

(0) ShareShare
ReportReport
Posted on by 171

how to debug a java script step by step

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    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

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • Community Member Profile Picture
    on at

    Use Fiddler tool for step 3 .

    pastedimage1595254057994v1.png

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans