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)

Simple Math (JavaScript)

(0) ShareShare
ReportReport
Posted on by

I'm trying to learn JS and create a simple JS function to add up 8 fields and put the total into a variable TT and update a field Total Time with that variable.  

I have it set for onsave on the form but the field is not updating.  These are all whole number/duration fields.  Is there some problem with my JS?

function Form_OnSave() {
// All all of the duration fields in the form

var tt =
(Xrm.Page.getAttribute("new_billabletime").getValue() +
Xrm.Page.getAttribute("new_billabletraveltime").getValue() +
Xrm.Page.getAttribute("new_mfgrwarrantytime").getValue() +
Xrm.Page.getAttribute("new_lunchandbreaks").getValue() +
Xrm.Page.getAttribute("new_warrantytime").getValue() +
Xrm.Page.getAttribute("new_ojttime").getValue() +
Xrm.Page.getAttribute("new_billabletimeot").getValue() +
Xrm.Page.getAttribute("new_billabletraveltimeot").getValue());

Xrm.Page.getAttribute("new_totaltimeaccountedfor").setValue(tt);
}

Thank you

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ganeshm Profile Picture
    on at

    Hi daniel,

    i tried the same with two duration field it worked fine.

    I suggest you to try with a debugger; to find the error.I think you must have got one of the field name wrong. 
    Best run the code in the console of your browser developer tool to find the error faster.

  • Suggested answer
    AbiRami Profile Picture
    516 on at

    yes. Its working fine. Use debugger to find the exact error. Refresh your page after save

    Thanks

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at

    Hi Daniel

    In that some of the control value is null or empty string. Is there any error throws?

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    If your new_totaltimeaccountedfor is disabled, the value will not be saved. You have to setSubmitMode for this field to "always".

  • Daniel at VNS Profile Picture
    on at

    Thank you all for the responses.  I realized after sending this that the script itself had no issues - this was a layer 8 issue, as it'd been a 16-hour day and I wasn't thinking straight.  :)

    A couple of you said 'use the debugger'.  Easy for you to say!  Which debugger?  Where is it?  

    Thank you

  • Daniel at VNS Profile Picture
    on at

    Thank you Guido.  I thought my code looked a little fat but being a JS newbie, it's all about functionality before form for me.  I appreciate your input on this - your code works perfectly.  And W3Schools has been great.

    I've also found this: www.webtoolkitonline.com/javascript-tester.html

    And this: codebeautify.org/jsvalidate

    To be helpful in checking my code.

  • Verified answer
    AbiRami Profile Picture
    516 on at

    Hi,

    To debug custom JavaScript code in CRM using browser developer tools:
    1. Add "debugger;" word in the start of your required function
    2. Refresh the CRM Page(Click F5)
    3. Open debugger tool(Click F12 or Right click->inspect)
    4. Refresh your CRM page once again
    5. Select the Sources tab in the developer tools
    6. Now whenever the function is called, control comes to the debugger
    7. Also u can add breakpoint by clicking on the line number on the left (adds a little blue marker)

    Then during execution debugging you can do a handful of stepping motions.

    F8 Continue: Will continue until the next breakpoint
    F10 Step over: Steps over next function call (won't enter the library)
    F11 Step into: Steps into the next function call (will enter the library)
    Shift + F11 Step out: Steps out of the current function

    Also refer the following link
    www.youtube.com/watch

    This method of debugging has slight difference. Instead of adding "debugger;" word in your code, search the required function in developer tools-> add breakpoints manually-> Refresh.

    Thanks

  • Daniel at VNS Profile Picture
    on at

    Thank you Abi.

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