Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How can I know what is going wrong with my Javascript in the Handler of fields?

Posted on by Microsoft Employee

How can I know what is going wrong with my Javascript in the Handler of fields? 

Can I add anything to alert the error message out in the Javascript?

Million Thanks~!!!!! 

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    Hi Mary,

    Prior to CRM 2013, you would need to do this via JavaScript.

    function calculate ()
    { 
     var val1 = Xrm.Page.getAttribute(‘new_val1′).getValue(); 
     var val2 = Xrm.Page.getAttribute(‘new_val2′).getValue();
     if(val1==null)return; 
     if(val2==null)return;
     var result = val1 + val2; 
     Xrm.Page.getAttribute(‘new_totalvalue’).setValue(result);
    }

    From CRM 2013, you could use Business Rules for the same.

    1614.Business-Rules-Calculate-Multiple-Field-1.png

    From CRM 2015 onwards, Calculated fields were introduced.

    Calculated Fields in Dynamics CRM 2015

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    How about if I am using the version before? Thanks!

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    Hi Mary,

    From CRM 2015 onwards, a new Field Type is introduced called Calculated Field. You could use this field to find the sum of several fields instead of writing Javascript for the same.

    See: http://www.powerobjects.com/2014/11/17/calculated-fields-in-dynamics-crm-2015/

    If you need javascript itself, try the code below.

    function calculate ()
    { 
     var val1 = Xrm.Page.getAttribute(‘new_val1′).getValue(); 
     var val2 = Xrm.Page.getAttribute(‘new_val2′).getValue();
     if(val1==null)return; 
     if(val2==null)return;
     var result = val1 + val2; 
     Xrm.Page.getAttribute(‘new_totalvalue’).setValue(result);
    }

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    Alex, may I know how to calculate the sum of several fields by a Javascript Function? How to add more than one parameter and calculate the sum? Thanks!

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    Yes, it will stop (once you close the alert, it will continue)

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    Thanks Alex, will the script stop running if I add alert to it?

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: How can I know what is going wrong with my Javascript in the Handler of fields?

    Hi,

     there is some info here:

     crmbook.powerobjects.com/.../debugging-javascript-libraries

     In short,

     - add alert("message"); to your javascript to display a popup message

     - use F12 button to open dev tools in IE/chrome

     - add debugger; command anywhere in your javascript to make the script stop there (this works when you are using F12 from above)

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans