Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to capture datetime field using javascript

Posted on by 340

I want to know any javascript function to capture datetime field and populate to another datetime field

Very similar to capture text field and populating to another text field

*This post is locked for comments

  • Suggested answer
    Sandy Hello Profile Picture
    Sandy Hello 340 on at
    RE: How to capture datetime field using javascript

    Thanks Rajkumar

  • Suggested answer
    AbhiCode Profile Picture
    AbhiCode 492 on at
    RE: How to capture datetime field using javascript

    You can also try with business rule, mention in below screen

    15838.2.PNG

    Thanks

    Abhishek Bhansali

    Read my blog

  • Suggested answer
    AbhiCode Profile Picture
    AbhiCode 492 on at
    RE: How to capture datetime field using javascript

    Hi Sandy,

    You to get the DateTime and set it to another field. 

    function GetSetDateTime() {
    debugger;
    var birthday =Xrm.Page.data.entity.attributes.get('new_birthcertificatedate').getValue();
    Xrm.Page.getAttribute('new_birthday').setValue(birthday);
    }


    For more date function and common js, please visit dynamicspeople.wordpress.com/.../common-javascript-functions

    Thanks

    Abhishek Bhansali

    Read my blog

     

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: How to capture datetime field using javascript

    In Rajkumar's example, it should be:

     if (Date1 != null && Date1 != 'undefined')  {

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to capture datetime field using javascript

    // Example for set value

    function SetDate(fieldname) {

    var setdate = fieldname

      Xrm.Page.getAttribute(fieldname).setValue(setdate )

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to capture datetime field using javascript

    // example GetDate("createdon");

    function GetDate(fieldname) {

       return Xrm.Page.data.entity.attributes.get(fieldname).getValue();

    }

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: How to capture datetime field using javascript

    Hi Sandy,

    Consider using Calculated field or Business Rule, to achieve this.

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    Rajkumar Rajaraman 18,108 on at
    RE: How to capture datetime field using javascript

    otherwise try this:

    You can use simple Javascript code to set date field value.

    Here is sample code

    function SetDate2()

    {

     var Date1 =  Xrm.Page.getAttribute('new_date1').getValue();

     if(Date1 !=null || Date1 !='undefined')

     {

        Xrm.Page.getAttribute('new_date2').setValue(Date1);

     }

    }

    Call this function on your first date (field A) on change event and change new_date1 with

    Field A and new_date2 with Field B attribute name.

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    Rajkumar Rajaraman 18,108 on at
    RE: How to capture datetime field using javascript

    Try this:

    function onDateFieldAChange() {

       if (Xrm.Page.getAttribute('new_myDateFieldA').getValue() != null) {

          Xrm.Page.getAttribute('new_myDateFieldB').setValue(Xrm.Page.getAttribute('new_myDateFieldA').getValue());

      }

    }

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,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans