Set default time in Date/Time field on catalog

S_53
Kilo Guru

I have a date/time variable on a catalog request. I need to set the time default to 20:00:00 when a date is picked and user can update the time if wanted. I tried below script where it is setting the time to 20:00:00 but users are not able to override it. Time is getting locked.

Any thoughts? 

 

Catalog Client Script - OnChange of date/time field

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.setValue('AppOps_Requested_by_date', newValue.replace(/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/,"20:00:00"));

//Type appropriate comment here, and begin script below
}

12 REPLIES 12

Brian Lancaster
Tera Sage

You may want to take a look at this blog post.  It is for a script include that give you a lot of the same functionality you see in server side scripting for date / time fields.

Coleton
Kilo Guru

Try this.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
        var selGdt = new GlideDateTime(newValue);
        selGdt.setValue(newValue + " 20:00:00");

	g_form.setValue('AppOps_Requested_by_date', selGdt));
}

S_53
Kilo Guru

This is still setting to the current time when date is picked.

I just updated my response, try the updated version. Sorry about that.