Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Javascript autopopulate date in bank due date field

Posted on by Microsoft Employee

Hi All,

It will be helpful if you please help me with this small doubt. I want my CRM Form to show all fields to have a date which should be 10th day of month like 10/03/2018 in the field called due date. I am not able to write JS code, can anyone please help me.

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript autopopulate date in bank due date field

    Hi

    You can try the following code plz change the schema name and write the js onChange event on form properties

    function test()

    {

       var _ContractStartDate = Xrm.Page.getAttribute("new_contractstartdate").getValue();

       if (Xrm.Page.getAttribute("new_contractstartdate") != null) {

           var ContractStartDate = new Date(_ContractStartDate.getMonth() + 1 + "/10/" + _ContractStartDate.getFullYear())

           Xrm.Page.getAttribute('new_contractstartdate').setValue(ContractStartDate);

       }

       else {

           Xrm.Page.getAttribute('new_contractstartdate').setValue(null);

       }

    }

    Thanks,

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript autopopulate date in bank due date field

    Ha ha...i new it will work. It is simple javascript basics.

    You could read about it here more if you would like community.dynamics.com/.../javascript-basics

    Do remember to close the thread by marking the suggestion as helpful.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript autopopulate date in bank due date field

    I am so obliged. It worked like magic so many many thanks to you .. thanks a ton!!! You are great....

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript autopopulate date in bank due date field

    Thats fine...its a good sign. Trying refreshing a browser and see if this works.

    Verify tge name you have used fixADate is same as you have in the javascript

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript autopopulate date in bank due date field

    After trying to fill the date field I get this error

    204406.Capture.PNG

    sorry for bothering you...

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript autopopulate date in bank due date field

    Try adding it on load an see if it works. So if you add it on change tgen the code will execute when you change the value of that field.

    Hope this helps

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript autopopulate date in bank due date field

    36237.Capture.PNG

    That is how it showed and in the form properties , I made the event handler as onSave

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript autopopulate date in bank due date field

    Can you share some screenshot. I am suspecting that you have added it as an onchange of field?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript autopopulate date in bank due date field

    I had used the code in events of the required field "suc_paymentduedate" instead of "new_duedate and saved and published. Then reloaded my form to do the testing but my field PaymentDueDate is still blank :(

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript autopopulate date in bank due date field

    Coudl you please share the steps you have followed. It should either work as expected or throw some error.

    How did you add this script on your form? Did you publish the changes?

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