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)

Javascript question

(0) ShareShare
ReportReport
Posted on by

Hello,

we have a javascript that is meant to calculate a field based on other field values, but every time i try to enable it on an OnSave or Onload control i get an undefined error, i cant see anything wrong with the javascript myself but i could be missing something.

function CalcProjDaysLeft()
{
  var nDP = Xrm.Page.getAttribute("new_pm_outstanding").getValue();
  var nPI = Xrm.Page.getAttribute("new_devdaysleft").getValue();
  var nDI = Xrm.Page.getAttribute("new_train_outstanding").getValue();

  if((nDP == null) || (nDD == null))
  {
    return;
  }
  Xrm.Page.getAttribute("new_daysleft").setValue (nDP + nPI + nDI);   
}

Is the script, any help would be greatly appreciated.

*This post is locked for comments

I have the same question (0)
  • ScottDurow Profile Picture
    21 on at

    You have no test for nPI being null - also are you sure all of those attributes are on the form?

  • Community Member Profile Picture
    on at

    I noticed that bit just after i posted it and amended the script accordingly - still getting the same error.

    The attributes are on the form - the schema names have capitals instead of all lower case (the ones on the actual form are lower case)

    To be honest i didn't write this it was there before i started.

  • slx Profile Picture
    386 on at

    What is the error ?

    Maybe you can also check that the values are numeric/decimal before the sum.

  • Community Member Profile Picture
    on at

    Error is just undefined - Yes the values are all decimal

  • ScottDurow Profile Picture
    21 on at

    Check that the webresource is published and that the reference in the onsave and onload event have the current function name.

    If you put a 'debugger' statement in your javascript and press F12 in the browser, you should be able to debug it.

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