Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

Get Month | Day | Year from a Date field in CRM using JavaScript.

Posted on by 70

 Hi All

I’m bit new to JScript, trying to calculate year, month and date from DOB field, I picked up the link from below, and tried it, could any one suggest if this is correct as I’m experiencing error

community.dynamics.com/.../get-month-day-year-from-a-date-field-in-crm-using-javascript

osplitDateandTime = {
    splitDateofBirth : function(exeecutionContext){
    //debugger;
    var formcontext = executionContext.getFormcontext();
    if(formcontext.getAttribute("new_dateofbirth")){
    var datefieldValue = formcontext.getAttribute('new_dateofbirth').getValue();

    if(dateFieldValue !==null){
    var yearDOB = dateFieldValue.getFullYear().toString();
    var monthDOB = (datefieldValue.getMonth()+ 1).toString();
    var dayDOB = dateFieldValue.getDate().toString();

    FormContext.getAttribute("dcuk_year").setValue("yearDOB");
    FormContext.getAttribute("dcuk_monthdob").setValue(("0"+ monthDOB).slice(-2));
    FormContext.getAttribute("dcuk_datedob").setValue(("0"+ dayDOB).slice(-2));

    } else {

        FormContext.getAttribute("dcuk_year").setValue(null);
        FormContext.getAttribute("dcuk_year").setValue(null);
        FormContext.getAttribute("dcuk_year").setValue(null);
    
    }
    }
    }
};

Thanks

Jag

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans