in custom table i want to prevent sumbit if start date(custom field) is > end date(custom field)

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

   var s=g_form.getValue('u_sdate');
   var e=g_form.getValue('u_edate');
   var flag=0;
   if(e<s)
   {
    g_form.showFieldMsg('u_sdate','Start date must be greate than start date');
    flag=1;
   }
   if(flag==1)
   {
    g_form.submit(false);
   }
   else{
    g_form.submit();
   }


   } i want to cancel submission until start date must less than end date using  single client script 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@aditya2byte 

you can use single onSubmit client script for this

function onSubmit() {
	//Type appropriate comment here, and begin script below

	g_form.hideErrorBox('u_sdate');
	g_form.hideErrorBox('u_edate');

	if(g_form.getValue('u_sdate') != '' && g_form.getValue('u_edate')){
		var start = new Date(g_form.getValue('u_sdate')).getTime();
		var end = new Date(g_form.getValue('u_edate')).getTime();
		if(end < start){
			var message = 'Please give valid start and end dates';
			g_form.showErrorBox('u_sdate', message);
			g_form.showErrorBox('u_edate', message);
			return false;
		}
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

Thank you , it works😇

aditya2byte_0-1756397271244.png