Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

Posted on by 2,645

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

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    Hello,

    Have a look below article-

    www.powerobjects.com/.../how-to-add-a-calculated-date-on-a-date-field-with-workflow

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    Should have also said that I have the workflow created, just unsure on how to get the field to be updated to the next year correctly if the workflow runs.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    Sorry, another question....I now need to create a workflow that when certain criteria is met that it sends an email to a user, as well as update the nhs_jsonfiledate field to be the next year.  

    Example, so if it runs on 9/1/2018, then the field would need to be updated to the next current year.

    Hope that makes sense.  Thanks for any additional help on this.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

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

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    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.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    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?

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    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

  • gdas Profile Picture
    gdas 50,085 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    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
    USA80 2,645 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    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?

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Script error: Unable to get property 'Initialize' of undefined or null reference at eval code

    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);           
            }


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans