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

S_53
Kilo Guru

Yes, it is setting to 20:00 with my script, but users are unable to override it. It is getting locked down.

you would have to find some way to make it so that the one change script does not run every time it changes.  unfortunately oldValue always returns null.

I thought of something.  I created a new checkbox variable and then wrapped my code in an if statement that check if that is true.  If it is not it runs and sets that value to true.   This will prevent it from running again.  It looks like this and then you can use a UI Policy with no conditions to always keep the checkbox variable hidden.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	
	//Type appropriate comment here, and begin script below
	if(g_form.getValue('onchange_datetime_ran') == 'false'){
		var dt = newValue.toString().split(' ');
		g_form.setValue('AppOps_requested_by_date', dt[0] + ' 20:00:00');
		g_form.setValue('onchange_datetime_ran', 'true');
	}
	
}