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
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.
From CRM 2015 onwards, Calculated fields were introduced.
Hope this helps.
How about if I am using the version before? Thanks!
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.
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!
Yes, it will stop (once you close the alert, it will continue)
Thanks Alex, will the script stop running if I add alert to it?
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)
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156