web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    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
    26 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
    26 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
    26 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
    50,091 Moderator 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
    34,477 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
    26 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
    50,091 Moderator 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
    26 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
    50,091 Moderator 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans