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)

Javascript getting year from date

(0) ShareShare
ReportReport
Posted on by
Hi, 
I need to set the year from the birthdate, month and day is setting the values correctly while the year is reading it right but don't set it. why ?
below is my script,
thank you


//==== Start OF: GetBirthdate============================================================= function GetBirthdate() { debugger; if(Xrm.Page.getAttribute("new_birthdate").getValue() != null) { var dateFieldValue= Xrm.Page.getAttribute('new_birthdate').getValue(); var year = dateFieldValue.getFullYear(); var month = dateFieldValue.getMonth()+1; var day = dateFieldValue.getDate(); //var dateOnly = new Date(year,month+1,day); Xrm.Page.getAttribute("new_birthday").setValue(day); Xrm.Page.getAttribute("new_birthmonth").setValue(month); Xrm.Page.getAttribute("new_birthyear").setValue(year); } else { Xrm.Page.getAttribute("new_birthday").setValue(null); Xrm.Page.getAttribute("new_birthmonth").setValue(null); Xrm.Page.getAttribute("new_birthyear").setValue(null); } }// end of function //==== END OF: Fill Birthday,BirthMonth and Birthyear if birthdate is filled

*This post is locked for comments

I have the same question (0)
  • ScottDurow Profile Picture
    21 on at

    Hi,

    When you say it doesn't set it - what do you mean. Do you get a null value or an error in the debug console.

    Check the data type of the attribute is compatible with the year value.

    Check that you have the correct attribute logical name.

  • Community Member Profile Picture
    on at

    53568.Capture.PNGno its not giving an error but the field remains empty. while day and month is filled

  • Suggested answer
    prt33k Profile Picture
    6,907 on at

    Hi Faith,

    Try using this:

    Xrm.Page.getAttribute("new_birthyear").setValue(year.toString())

    Thanks,

    Prateek

  • Community Member Profile Picture
    on at

    thanks Prateek still the same its empty

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi Faith,

    Please check your method is getting triggered or not?

    Regards

    Hemant

  • Durgaprasad Profile Picture
    80 on at
    Check whether the below variable has value in the debugging mode.
    var year = dateFieldValue.getFullYear();

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    probably the field name is not new_birthyear, check the field name that should store the year part

  • Suggested answer
    mvilas02 Profile Picture
    356 on at

    Hi ,

    I tried the following , and it works for me

    var dateFieldValue = Xrm.Page.getAttribute("createdon").getValue();
    var year = dateFieldValue.getFullYear();
    Xrm.Page.getAttribute("description").setValue(year.toString());

    Regards,

    Vilas Magar

  • Suggested answer
    prt33k Profile Picture
    6,907 on at

    I assume the new_birthyear is string type and you have published all customization.

    Can you point the year to month and see if the value is getting filled :

    Xrm.Page.getAttribute("new_birthmonth").setValue(year.toString());

    Thanks,

    Prateek

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock 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