AnsweredAssumed Answered

Setting current date and time on control

Question asked by benizzard on May 14, 2015
Latest reply on Jul 11, 2018 by sverem

Hi,

 

I'm trying to pre-fill the date & time for a date/time control on my form by using a button on my form. I don't want to use a default column value and I want the user to be able to pre-fill the field on a per-case basis.

 

What I've done so far is:

  1. Created a button on the form, with the action of 'JavaScript'

    Form Date.png

  2. Given the date/time control a Client ID
    dateTime Control.png
  3. Created the following function within the 'Custom JavaScript' section in Form Settings:
function setDateTime()
{ 
var fullDate = new Date()
var twoDigitMonth = ("0" + (fullDate.getMonth() + 1)).slice(-2)
var hours = fullDate.getHours();
var minutes = fullDate.getMinutes();
var currentDate = fullDate.getDate() + "/" + twoDigitMonth + "/" + fullDate.getFullYear();

if (hours   < 10) { hours   = "0" + hours;   }

/** Round down to the nearest 5 minutes. This is due to us rounding the minutes but not the hours. For example, 09:58 could be rounded up to 09:60 (invalid). Instead, 09:58 becomes 09:55.
**/
minutes = minutes - 2.5;
minutes = 5 * Math.round( minutes / 5 );

// Set the date field
NWF$('#' + fldDateClosed).val(currentDate);
// Set the time (hours + minutes) fields
NWF$('#' + fldDateClosed + ' + IMG + SELECT').val(hours);
NWF$('#' + fldDateClosed + ' + IMG + SELECT + SELECT').val(minutes);
// Set Incident Status
NWF$('#' + fldStatus).val('Completed');
}

 


Upon previewing, and clicking the 'Now' button on the form, it fills the input with the following:

Date Time on Form.png

 

Does anyone have any ideas as to how I can modify the hours and minutes on the form?

 

Thanks

Outcomes