Set default time on a date/time field

booher04
Tera Guru

Hello - is there an easy way to set a default time on the date/time field variable?  We have a need for the date picker to default to 8:00am EST when you open the calendar to pick the date/time.

1 ACCEPTED SOLUTION

I got it working using below script

function onLoad() {
	var ajax = new GlideAjax('MyDateTimeAjax');
	ajax.addParam('sysparm_name', 'nowDateTime');
	ajax.getXML(function () {
		var test = ajax.getXMLAnswer(function(answer){
			var response = JSON.parse(answer);
			//alert(response.datetime);
			g_form.setValue('date_time_deployment', response.datetime);
		});
	});
}
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	nowDateTime: function () {
		var Date = new GlideDate(); 
		var datetime = (Date + ' 08:00:00');
		var response = {};
		response.datetime = datetime;
		return JSON.stringify(response);
	},
	type: 'MyDateTimeAjax'
});

View solution in original post

15 REPLIES 15

Do you have client script that has ui type set to All.

find_real_file.png

Right now it's set to Desktop, not All.  

you need to set it to all so it works on both. (portal and desktop)

also try

var date = ajax.getAnswer() + ' 08:00:00';

g_form.setValue('date_time_deployment', date);

I removed the other script and added this.. it didn't work either.