End date is greater than OR equal to the start date

SivaKumar123
Tera Contributor

End date is greater than OR equal to the Start date, I have used below script its not working for Equal function.

only working on the greater than function.

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var end = g_form.getValue('start_date');
    var start = g_form.getValue('end_date');

 

    if (end >= start) {
        alert("Start date is greater than OR equal to End date.");
        g_form.clearValue('end_date');
    }

}

1 ACCEPTED SOLUTION

@SivaKumar123 

same script just modify

1) onChange client script on End date

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	g_form.hideErrorBox('start_date');
	g_form.hideErrorBox('end_date');

	if(g_form.getValue('start_date') != '' && g_form.getValue('end_date')){
		var start = new Date(g_form.getValue('start_date')).getTime();
		var end = new Date(g_form.getValue('end_date')).getTime();
		if(end < start){
			var message = "Start date should be greater than OR equal to End date.";
			g_form.showErrorBox('end_date', message);
			g_form.clearValue('end_date');
		}
	}
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@SivaKumar123 

same script just modify

1) onChange client script on End date

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	g_form.hideErrorBox('start_date');
	g_form.hideErrorBox('end_date');

	if(g_form.getValue('start_date') != '' && g_form.getValue('end_date')){
		var start = new Date(g_form.getValue('start_date')).getTime();
		var end = new Date(g_form.getValue('end_date')).getTime();
		if(end < start){
			var message = "Start date should be greater than OR equal to End date.";
			g_form.showErrorBox('end_date', message);
			g_form.clearValue('end_date');
		}
	}
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@SivaKumar123 

Please mark my response as correct as my script worked for you.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader