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)

Set Date to today's date only first time the form is loaded

(0) ShareShare
ReportReport
Posted on by

Hi everyone!

I would like to set a date field to today's date only when the form is loaded the first time, so that when i open again the form to not change the date with the new today's date.

This will have to be done with javascript but how? Created on date in only available after the item is created. I want to set default date to today and also to be changeable , so that the user will change it. 

One idea is to have an index to increment it when form is loaded only when index is 1 will run, the first time. Not sure if there is a more optimized way

Any ideas?

*This post is locked for comments

I have the same question (0)
  • sandeepstw Profile Picture
    4,601 on at

    Hi,

    You can use javascript web resource and set field value as today date. Associate web resource on form load. Check this link:

    http://www.cobalt.net/using-javascript-to-populate-fields-on-form-load-in-microsoft-crm/

    Thanks,

    Sandeep

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Shak,

    You could create a calculated date time field to set the value to today's date.

    See: community.dynamics.com/.../190532

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    If I got you right you want to set the field when it's created for the first time. If so then I would suggest you use formType control instead of using a counter. 

    function SetDate(){
     if (Xrm.Page.ui.getFormType() == 1) 
        {
           your code to set date 
        }
    }


    Hope it helps

    Ezgi Haglund
    Please verify if it solves your problem

  • Suggested answer
    Community Member Profile Picture
    on at

    Use this code:

    function SetTodaysDate(){

    if (Xrm.Page.ui.getFormType() == 1)

       {

    var Date = Xrm.Page.data.entity.attributes.get("fieldname");

    var today = new Date();

    Date.setValue(today );

       }

    }

    Refer this for form types:

    www.mscrmconsultant.com/.../get-form-type-using-javascript-in-crm.html

  • Franglais Profile Picture
    on at

    What is the purpose of the field?

  • Suggested answer
    Rahul G J Profile Picture
    605 on at

    Hi Shak,

    That's Right1 what Ezgi HAGLUND and Mohd Saad Akhtar they said.

    Regards,

    Rahul

  • Community Member Profile Picture
    on at

    Using Date you get a message that Date is not a constructor.

    Using this code worked fine:

    function SetTodaysDateOnLoad(){

    Xrm.Page.getAttribute("new_todaysdate").setValue(Date.now());

    }

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