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)

'undefined' error on first custom JavaScript

(0) ShareShare
ReportReport
Posted on by 185

I'm trying to add my first custom JavaScript to a form field.  I added this source code as a Web Resource to my custom solution:

function nmc_setSuppItemSubmissionDate() {
   debugger;
   var submissionStatus = Xrm.Page.getAttribute("datatel_submissionstatus").getValue();
   var submissionDate   = Xrm.Page.getAttribute("datatel_submissiondate").getValue();
   
   if (submissionStatus == "Received" || submissionStatus == "Waived" || submissionStatus == "Approved") {
      if submissionDate == "" {
         var currentDateTime = new Date();
         Xrm.Page.getAttribute("datatel_submissiondate").setValue(currentDateTime);
      }
   }
   else {
      Xrm.Page.getAttribute("datatel_submissiondate").setValue(null);
   }

In the list of Web Resources, it has a Display Name of SetSupplementalSubmissionDate and a Name of nmc_setSubmissionDate.

I then went into the:

  • Form Properties Events tab and added nmc_setSubmissionDate to the Form Libraries
  • Field Properties Events tab of the datatel_submissionstatus field and added the library nmc_setSubmissionDate and function nmc_setSuppItemSubmissionDate 
    to the OnChange event

I saved and published the form.  When I change the datatel_submissionstatus field in the form, I get the error:

There was an error with this field's customized event:  Field: datatel_submissionstatus  Event:onchange
Error:'nmc_setSuppItemSubmissionDate' is undefined.

I'm not sure what I'm doing wrong.  If anyone could explain this, I would be grateful.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    When you load the page, press f12, choose the tab called "sources" and in the left you will see a folder called "[somenumbers]/WebResources" there you will see your javascript, click in the count of the first rows to add a break point, then fire your OnChange, when you breakpoint works, go pressing f10 to execute line by line, and then you will see exactly in what line your error is, then you can work to fix it.

    the only thing I'm finding strange in your code is the first line where you put "debugger", I don't know this command, but I may be missing something.

    I hope I helped.

  • Verified answer
    Abhishek_Sinha Profile Picture
    665 on at

    Hi,

    Are u able to debug? press F12 and check this error . This error comes because of syntax problem also  .  Put alert after each line to check where it's failing if  unable  to debug.  Same functionality you can also achieve  by using business rules. Hope it helps

  • ljc Profile Picture
    185 on at

    Yes you did help JoaoL!

    Thank you for checking my code and for the debugging tips!

    It turns out I did have a syntax error with one of my IF statements.

    p.s. I found the "debugger" suggestion on this page:  social.technet.microsoft.com/.../3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx

    I didn't get that to work, though

  • Suggested answer
    ljc Profile Picture
    185 on at

    Thank you for mentioning that the error could be a syntax issue also.  I assumed I did not follow the correct steps when creating my JavaScript function or that I had entered a library or function name in the wrong place...

    It was a syntax error.  Your suggestion on using alerts was also helpful.

    Thanks you for sharing your knowledge and time.

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