Date Time Picker customization

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2012 07:35 AM
From a request we had by the process owners of change, we developed a onLoad client script to set the DateTime picker to default to zeros on the time entry so when the icon is clicked, the time is defaulted to 00:00:00 in the popup.
Here is our current code
function onLoad() { setDatePickerTime('start_date'); setDatePickerTime('end_date'); setDatePickerTime('requested_by_date'); setDatePickerTime('work_start'); setDatePickerTime('work_end'); function setDatePickerTime(field){ //Attach an event listener to set default time value for date picker Event.observe(g_form.getControl(field).next('a'), 'click', function() { $('GwtDateTimePicker_hh').value = '00'; $('GwtDateTimePicker_mm').value = '00'; $('GwtDateTimePicker_ss').value = '00'; }); } }
Works fine in Aspen, but not in Berlin. We are getting java errors in IE and although we do not get errors in Chrome/Firefox, it does not change the time entries to zeros.
Does anyone have any ideas what changes I might make to allow this to work again in Berlin?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2012 07:43 AM
This solution comes from SNGuru. It has to do with the timing of form loads in Berlin (which breaks prototype's 'Event.observe' in a lot of cases). I've coded a workaround that you can find here.
http://www.servicenowguru.com/scripting/client-scripts-scripting/set-default-datetime-picker-dialog-time/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2012 07:55 AM
The one time I do not search the SNCGuru site...
Thanks for the update to the script. Another admin had created this in our system, so I wasn't sure where to look.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2013 01:48 PM
Hi, I tried this in a Berlin system and my script ended up looking like the following (it would be nice to have a system property that sets this globally):
function onLoad() {
//Type appropriate comment here, and begin script below
setDatePickerTime('requested_by_date');
}
function setDatePickerTime(field){
//Attach an event listener to set default time value for date picker
Event.observe(g_form.getControl(field).next('a'), 'click', function() {
setTimeout(function() {
$('GwtDateTimePicker_hh').value = '00';
$('GwtDateTimePicker_mm').value = '00';
$('GwtDateTimePicker_ss').value = '00';
});
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2013 08:39 AM
Looking for some assistance with the above. Setting the default date and time works fantastically!
What I am looking to do is set the default AM/PM for a specific time. I've tried adding something along the lines of:
$('GwtDateTimePicker_a').value = 'PM';
That does not appear to be the appropriate method.
Thanks