web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

(0) ShareShare
ReportReport
Posted on by 26

Below is my script, the field is populating correctly when the form loads, however I also get the script error: Unable to get property 'Initialize' of undefined or null reference at eval code.  I am not sure why I am getting this and F12 debugger doesn't show any errors.  Any ideas?

function setJSonDate()
 {
  var currentYear = (new Date()).getFullYear();
  var sept1st = new Date(currentYear, 8, 1);
  
  Xrm.Page.getAttribute("nhs_jsondatefield").setValue(sept1st);
 }

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello ,

    I am not sure why the error coming , your code is correct.  Seems datetime control is not initializing . Could you please try with this -

            function setJSonDate() {
                setTimeout(function () {
                    var d = new Date();
                    var currentYear = d.getFullYear();
                    var sept1st = new Date(currentYear, 8, 1);
                    if (Xrm.Page.ui.controls.get("nhs_jsondatefield") != null)
                        Xrm.Page.getAttribute("nhs_jsondatefield").setValue(sept1st);
                }, 2000);
            }


  • USA80 Profile Picture
    26 on at

    I tried what you mentioned, but received the same error yet.

  • USA80 Profile Picture
    26 on at

    the field is on the form, it is visible, and it is a Date Only field.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello ,

    Try with this  , seems the problem is you are setting datetime field , I have made this date only now . Hope this will work.

            function setJSonDate() {           
                    var d = new Date();
                    var currentYear = d.getFullYear();               
                    var sept1st = "09" + "/" + "01" + "/"+ currentYear; // MM/DD/YYYY - This depends on which format are you displaying
                    var Sept1StDateOnly = new Date(sept1st);               
                    if (Xrm.Page.ui.controls.get("nhs_jsondatefield") != null)
                        Xrm.Page.getAttribute("nhs_jsondatefield").setValue(Sept1StDateOnly);           
            }


  • USA80 Profile Picture
    26 on at

    Still same issue.  When I look into the debugger again, I see an error under the Console Tab.  When I go there, I see an error that says, "Script1002: Syntax error

                    File: formscript.js.aspx, Line: 1, Column: 1

    When I went to this location on this script line 1 is the following:

    <!DOCTYPE HTML>

    Any ideas?

  • gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Could you please debug your code , let me know which line you are getting error .

    Write "debugger;" in your code and press F12 window , it will automatically start debug when  page load .

  • USA80 Profile Picture
    26 on at

    I just did that and the code itself there is no errors, it is error on the script that I mentioned above on line one, which I put above what line is.

    Still same issue.  When I look into the debugger again, I see an error under the Console Tab.  When I go there, I see an error that says, "Script1002: Syntax error

                   File: formscript.js.aspx, Line: 1, Column: 1

    When I went to this location on this script line 1 is the following:

    <!DOCTYPE HTML

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi Usa,

     did you try removing your script (and the corresponding onLoad event)? I am wondering if it has anything to do with the error at all or if it's something else.

    Is it the only onLoad event for that form? Is it the only web resource attached to the form? If it is, could you post all the code you have in that web resource?

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Seems the error is coming from your javascript web resource file , something brackets or may be some structure of JS is wrong in the file .  In addition try to search with "Initialize" , somewhere it has written in the JS file , put null check of the object where you are finding "Initialize"from object.

  • USA80 Profile Picture
    26 on at

    Thanks guys, I resolved the error. I recreated by Web Resource which seemed to solve the issue.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans