locked
Getting Date field to default to currrent date.... RRS feed

  • Question

  • Hi,

    I am trying to find where to setup a date field to automatically default to current date when loading the form, but still allow the user to change the date if needed..

     


    Cheers and regards Rossco
    Sunday, March 28, 2010 9:12 PM

Answers

  • In the onload event of your entity form you would need to run this javascript (where datefield is the name of your date attribute):

    if (crmForm.all.datefield)
         crmForm.all.datefield.DataValue = new Date();

    • Marked as answer by GrenadaV Sunday, March 28, 2010 10:40 PM
    Sunday, March 28, 2010 9:47 PM

All replies

  • In the onload event of your entity form you would need to run this javascript (where datefield is the name of your date attribute):

    if (crmForm.all.datefield)
         crmForm.all.datefield.DataValue = new Date();

    • Marked as answer by GrenadaV Sunday, March 28, 2010 10:40 PM
    Sunday, March 28, 2010 9:47 PM
  • I'd use the following to make sure the date isn't overwritten if a value is already in the field

    if (crmForm.all.datefield.DataValue != null)
         crmForm.all.datefield.DataValue = new Date();


    MSCRM Bing'd - http://bingsoft.wordpress.com
    • Proposed as answer by Linn Zaw Win Wednesday, March 7, 2012 2:26 AM
    Sunday, March 28, 2010 9:59 PM
    Moderator
  • Brilliant, thanks both of you, much appreciated :-)
    Cheers and regards Rossco
    Sunday, March 28, 2010 10:37 PM
  • Hi there,

    I tried implementing this onload event script to the form but it seems there is a need to load a library first to the form. I am not a developer so I am not sure what library should be added.

    I need to add today's date to a couple of forms when there is new record created.

    Thanks

    Tuesday, March 6, 2012 4:14 PM
  • Hello HS2010,

    you will see the source in this link: 

     http://blogs.infinite-x.net/2012/02/10/set-the-fields-default-date-and-time-using-javascript/

    You must follow this steps:
    1) Open your solution (or the main solution)
    2) create a new web resource (Type = Script/JScript)
    3) open the text editor and copy the source code for both (!) function in the text editor (Change the field name if you work with an other entity)
    4) Save and publish  the web resource
    5) Go to the form of the entity (in the example it is the task entity)
    6) Open the form properties (you will find the button at the ribbonbar)
    7) You will see the formproperties (have a look at the sreenshot in the link)
       Add the new defined webressource in the area of FormLibraries
       At the area EventHandler: Form / Onload / add
       Select the library and type the function name in the second line
       save & Publish


    Herzliche Grüße / Best regards Markus Müller If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by HS2010 Thursday, March 8, 2012 7:33 PM
    Tuesday, March 6, 2012 9:22 PM
  • Thank you very much Markus for the details, this surely helps.
    Thursday, March 8, 2012 7:35 PM