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)

Auto-populate text fields based on a date field

(0) ShareShare
ReportReport
Posted on by

Hi Community,

On my Opportunity form I have a custom date field .

I also have 2 custom text fields called Month and Year.

How do I auto-populate the Month and Year fields with values based on the date field?

Example 1:

Date Field user selects 01/01/2014

Month auto-populates with 'January'
Year auto populates with '2014'

Example 2:

Date Field user selects 12/12/2015

Month auto-populates with 'December'
Year auto populates with '2015'


Cheers,
VVG

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Saroj Das Profile Picture
    3,355 on at

    Hello, on dateField onchange event call the function. If required, modify as per your requirement.

    function getMonthYear(){

    var dateVal=Xrm.Page.getAttribute(dateField).getValue();

    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];

    if(dateVal!=null ){

    var data=dateVal.split('/');

    if(data.length>0){

    // for example your date is in dd/mm/yyyy format

    // 31/12/2013

    var mth=months[data[1]-1];

    var yr=data[2];

    Xrm.Page.getAttribute('monthField').setValue(mth);

    Xrm.Page.getAttribute('yearField').setValue(yr);

    }

    }

    }

    hth

    Thanks,

    Saroj

  • Royal King Profile Picture
    27,686 on at
    function FormatDate(fieldname) {
        var d = Xrm.Page.data.entity.attributes.get(fieldname).getValue();
        if (d != null) {
                   var months =  ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
            var  date = d.getDate();
            var curr_month = d.getMonth();       
            var year = d.getFullYear();
            var month= months[curr_month] ;
        }
        else return null;
    }
  • Community Member Profile Picture
    on at

    Thanks Guido!

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