Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to validate end time should be greater than start time in hh:mm? client script for this

Chaitra k1
Kilo Explorer

If the user chooses start time which is greater than the chosen end time then , message has to dispaly saying end time should be greater than start time in the client script

time is given in drop down as hh:mm for both start and end time

2 REPLIES 2

Shakeel Shaik
Giga Sage
Giga Sage

Hi @Chaitra k 

 

 Once check this below link for reference

A Date field Should not allow Past Dates using Client Script in ServiceNow

 

If my response is helpful, then Please mark as Correct Answer/Helpful.

Please check and let us know.

Thanks 🙂

Shakeel Shaik.

Thanks,
Shakeel Shaik 🙂

Community Alums
Not applicable

Hi @Chaitra K ,

You can use this onChange script on the start date:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	
	if (isLoading || newValue == '') {
		
		return;
	}
	
	var end = g_form.getValue('due_date');
	var start = g_form.getValue('u_planned_start_date');
	var format =  g_user_date_time_format;
	var isEndBeforeStart = compareDates(start, format, end, format);
	
	
	// skip if start and end is blank
	
	if (start == "" && end == "") {
		
		return;
	}
	
	// skip if start is not blank and end is blank
	
	if (start != "" && end == ""){
		
		return;
	}
	
	if (isEndBeforeStart) {
		g_form.setValue('u_planned_start_date', '');
		
		alert("Planned start date must be before Planned end date.");
		
		
	}
}

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep