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)

Unable to get property 'getfullyear' of undefined or null reference...

(0) ShareShare
ReportReport
Posted on by 26

I have the following line: 

var year = CarrierStartDate.getFullYear();      

but when my form loads I get an error message that says, "Unable to get property 'getfullyear' of undefined or null reference"

Any ideas why?

*This post is locked for comments

I have the same question (0)
  • USA80 Profile Picture
    26 on at

    Here is more of the code:

           var CarrierStartDate = Xrm.Page.getAttribute("nhs_carrierstartdate").getValue();

    var year = CarrierStartDate.getFullYear();

    var month = CarrierStartDate.getMonth();

    var day = CarrierStartDate.getDate();

    var dateOnly = new Date(year,month,day);

  • Suggested answer
    Community Member Profile Picture
    on at

    The error is because CarrierStartDate does not contain any value when you are trying to call the .getFullYear()

    1. Check if there is any value in your field when the form loads

    2. Check if "nhs_carrierstartdate" is 100% the correct fieldname

    3. Add an if statement to check if the field contains any value before trying to use that value

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

    Hi,

    In addition I am suspecting that the "CarrierStartDate" value has not  been converted to date object and its unable to get the "getFullYear" method from the value.

    So try to convert date object and then use "getFullYear" method. Here is sample code -

                var CarrierStartDate = Xrm.Page.getAttribute("new_dateFieldName").getValue();
                if(CarrierStartDate !=null && CarrierStartDate != undefined)
                {
                    var DateValueWithFormat = new Date(CarrierStartDate); // Convert Date Object from value 
                    var YearValue = DateValueWithFormat.getFullYear();  // Get Year Value
                }


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

    Here is your final code -

                var CarrierStartDate = Xrm.Page.getAttribute("nhs_carrierstartdate").getValue();
                if(CarrierStartDate !=null && CarrierStartDate != undefined)
                {
                    var DateValueWithFormat = new Date(CarrierStartDate); // Convert Date Object
                    var year = DateValueWithFormat.getFullYear();
                    var month = DateValueWithFormat.getMonth() + 1; 
                    var day = DateValueWithFormat.getDate();
                    var dateOnly = new Date(year,month,day);
                }


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