locked
New Field - Time Only RRS feed

  • Question

  • I see that there is no option on the datetime field for time only.  Is there a way around this?

    I don't really want to go down the route of using a text field and javascript.

    I also don't want to just have users ignore the date part.

    Any suggestions?

    Tuesday, March 24, 2009 11:17 AM

Answers

  • You are correct, there is no choice for time only.  Just date/time, and you can display date only or date and time.

    Your options are:
    1.  add a date/time field and use javascript to hide the date part.  You would have to have your javascript populate the date, because the time is not available to be selected until a date is entered.
    2.  Create a picklist and enter a picklist item for every available time.  If say you wanted users to be able to select a time between 8 and 5, at 15 minute increments that would be 36 picklist items. 
    3.  Give them a text field to enter their time. 

    It really comes down to what do you want to do with this field.  If you want the time to trigger something, such as a workflow at the time that is entered, you need to use a datetime field.  if the time is more of a data point on a record, then a picklist or text field should work.

    If you want to use the time to schedule something, like a workflow, maybe labeling it a little differently would make a traditional date time field make more sense.  For example, say I want the record to schedule a workflow that runs daily at a given time, i would call my date field "start date" meaning whatever date/time that is entered is where the process starts.
    Tuesday, March 24, 2009 11:34 AM
    Moderator
  • You can use the Internet Explorer Developer Toolbar to identify the exact name of that field. You can then set that to hidden.
    Tuesday, March 24, 2009 10:59 PM
    Moderator
  • Did you end up getting around the not saving exit crash?

    I used your snippet with a slight change and got it to work

    var CRM_FORM_TYPE_CREATE = 1;
    
    var CRM_FORM_TYPE_UPDATE = 2;
    
    
    
    switch (crmForm.FormType)
    
    {
    
      case CRM_FORM_TYPE_CREATE:
    
        crmForm.all.new_defaultstarttime.DataValue = new Date();
    
        crmForm.all.new_defaultstarttime.all.DateInput.swapNode(crmForm.all.new_defaultstarttime.all.time);
    
        crmForm.all.new_defaultstarttime.all.DateInput.style.width = '0px';
    
        crmForm.all.new_defaultstarttime.all.new_defaultstarttimeimg.outerHTML = '';
    
        break;
    
      case CRM_FORM_TYPE_UPDATE:
    
        crmForm.all.new_defaultstarttime.all.DateInput.swapNode(crmForm.all.new_defaultstarttime.all.time);
    
        crmForm.all.new_defaultstarttime.all.DateInput.style.width = '0px';
    
        crmForm.all.new_defaultstarttime.all.new_defaultstarttimeimg.outerHTML = '';
    
        break;
    
    }
    
    Thursday, April 16, 2009 1:11 AM

All replies

  • You can add a regular datetime field , set the date in advance (current date) and let the user select the relevant time. this will only require you to add the following js when the form loads:
    crmForm.new_dateattribute.DataValue = new Date();
    Tuesday, March 24, 2009 11:25 AM
  • You are correct, there is no choice for time only.  Just date/time, and you can display date only or date and time.

    Your options are:
    1.  add a date/time field and use javascript to hide the date part.  You would have to have your javascript populate the date, because the time is not available to be selected until a date is entered.
    2.  Create a picklist and enter a picklist item for every available time.  If say you wanted users to be able to select a time between 8 and 5, at 15 minute increments that would be 36 picklist items. 
    3.  Give them a text field to enter their time. 

    It really comes down to what do you want to do with this field.  If you want the time to trigger something, such as a workflow at the time that is entered, you need to use a datetime field.  if the time is more of a data point on a record, then a picklist or text field should work.

    If you want to use the time to schedule something, like a workflow, maybe labeling it a little differently would make a traditional date time field make more sense.  For example, say I want the record to schedule a workflow that runs daily at a given time, i would call my date field "start date" meaning whatever date/time that is entered is where the process starts.
    Tuesday, March 24, 2009 11:34 AM
    Moderator
  • Number 1 sounds good - how can I disable the date part in javascript?

    I presume in the OnLoad() of the form:

    crmForm.all.new_myDateTimeField.datepart.visible = false;

    But what is the exact syntax?  If you could point me to a CRM object method browser of some sort I could look it up myself but I'm not aware of such a thing.
    Tuesday, March 24, 2009 12:12 PM
  • You can use the Internet Explorer Developer Toolbar to identify the exact name of that field. You can then set that to hidden.
    Tuesday, March 24, 2009 10:59 PM
    Moderator
  • I can't set the entire field to hidden - because I still want to see the time element of it.

    The I.E. Dev. Toolbar shows me the DIV elements, etc, but as far as I'm aware you can't hide DIV elements or cells.

    I've got a partial solution by using the following:

     
        crmForm.all.new_supportbeginsat.all.DateInput.swapNode(crmForm.all.new_supportbeginsat.all.time);  
        crmForm.all.new_supportbeginsat.all.DateInput.outerHTML = '';  
        crmForm.all.new_supportbeginsat.all.new_supportbeginsatimg.outerHTML = '';  
     

    The only remaining issue is that when I make a change to the time value on the form - and exit without saving it crashes.
    Wednesday, March 25, 2009 10:09 AM
  • Did you end up getting around the not saving exit crash?

    I used your snippet with a slight change and got it to work

    var CRM_FORM_TYPE_CREATE = 1;
    
    var CRM_FORM_TYPE_UPDATE = 2;
    
    
    
    switch (crmForm.FormType)
    
    {
    
      case CRM_FORM_TYPE_CREATE:
    
        crmForm.all.new_defaultstarttime.DataValue = new Date();
    
        crmForm.all.new_defaultstarttime.all.DateInput.swapNode(crmForm.all.new_defaultstarttime.all.time);
    
        crmForm.all.new_defaultstarttime.all.DateInput.style.width = '0px';
    
        crmForm.all.new_defaultstarttime.all.new_defaultstarttimeimg.outerHTML = '';
    
        break;
    
      case CRM_FORM_TYPE_UPDATE:
    
        crmForm.all.new_defaultstarttime.all.DateInput.swapNode(crmForm.all.new_defaultstarttime.all.time);
    
        crmForm.all.new_defaultstarttime.all.DateInput.style.width = '0px';
    
        crmForm.all.new_defaultstarttime.all.new_defaultstarttimeimg.outerHTML = '';
    
        break;
    
    }
    
    Thursday, April 16, 2009 1:11 AM
  • No I didn't!  I will have to try your mod's and see if it works.

    Many thanks,
    Friday, April 17, 2009 2:34 PM
  • I thought I'd got what PGO01 wanted working with the following code:

    var
    oDateTimeControl = crmForm.all.new_tidspunkt;
    oDateTimeControl.DataValue =
    new DateTime();
    oDateTimeControl.all.DateInput.style.visibility =

    "hidden";
    oDateTimeControl.all.new_tidspunktimg.style.visibility =
    "hidden";

    It works recently well also, but when clicking on the time field to edit the value I get the following error:

    "Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

    Have anyone solved this problem without getting this error?

    Tuesday, June 9, 2009 3:03 PM