locked
How to set Default value for Time in Date and Time Field RRS feed

  • Question

  • Hi ,

    Could someone pls tell me how can i set default value for  time in Date and Time Field.

    Monday, June 3, 2013 10:59 AM

Answers

  • Hi,

    Below code helped me.

    //Set the Time portion of a Date Field
    Xrm.Page.getAttribute(attributeName).setValue(new Date().setHours(8, 30, 0))
    • Marked as answer by mc.gem Monday, June 3, 2013 11:49 AM
    Monday, June 3, 2013 11:48 AM

All replies

  • Hi,

        For date and time field there is no default time setting. You can assign value to the field on form Onload event/ in plugin  though.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Minal Dahiya Monday, June 3, 2013 11:01 AM
    Monday, June 3, 2013 11:01 AM
  • Hi Minal,

    Thanks for the reply.

    Could you pls explain how can i assign value to a field on Form Onload event?

    Monday, June 3, 2013 11:20 AM
  • If you want to assign current datetime to a field you can use this code:

    Xrm.Page.getAttribute("fieldname").setValue(new Date());



    My blog: www.crmanswers.net

    Monday, June 3, 2013 11:24 AM
  • Hi Guido,

    Thanks for the Reply.

    I do not want to display current date and time.

    i want to set default value for time.

    Monday, June 3, 2013 11:26 AM
  • Hi,

        Following script will give you time.

    Xrm.Page.getAttribute("fieldname").setValue(new Date(),getTime());


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Minal Dahiya Monday, June 3, 2013 11:30 AM
    Monday, June 3, 2013 11:30 AM
  • Hi,

    Below code helped me.

    //Set the Time portion of a Date Field
    Xrm.Page.getAttribute(attributeName).setValue(new Date().setHours(8, 30, 0))
    • Marked as answer by mc.gem Monday, June 3, 2013 11:49 AM
    Monday, June 3, 2013 11:48 AM
  • I have a DateTime field the user enters the date.  I want to default the time portion after the user enters the date.  I am trying your code, but get an error "expected identifier". 

    Here is the code I am using:

    function ReminderDate_onchange()
    {

    Xrm.Page.getAttribute.("follett_reminderdate").setValue(new Date().setHours(22,0,0));

    }

    Any suggestions?


    Ken Compter

    Monday, June 17, 2013 10:03 PM
  • you have a dot between getAttribute and ("follet_reminderdate")

    My blog: www.crmanswers.net

    • Proposed as answer by VidhiyaM Tuesday, June 18, 2013 4:52 AM
    Monday, June 17, 2013 10:17 PM
  • Hi,

    Remove .dot after getattribute("") field.

    Tuesday, June 18, 2013 4:24 AM
  • Always the simple stuff that trips you up.  Thanks for the help!

    Ken Compter

    Tuesday, June 18, 2013 12:55 PM