We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to get today's date and abort submission if it exceeds 3months?

Kushi
Tera Contributor

Hello, 

I have a requirement for aborting the form submission, if the date field value entered is more than 3 months.

How do I implement this using client script?

1 REPLY 1

Harish KM
Kilo Patron

Hi @Kushi you can create a onSubmit client script:

Example:

var selectedDateNum = getDateFromFormat(newValue, g_user_date_format); //This gives the selected date
var ninety_days =129600; //90 days in minutes
var ninety_days_date = new Date(new Date().getTime() - ninety_days*60000);
var ninety_days_dateStr = formatDate(ninety_days_date, g_user_date_format);
var ninety_days_dateNum = getDateFromFormat(ninety_days_dateStr, g_user_date_format);
if(selectedDateNum < ninety_days_dateNum) {
alert("Selected date cannot be less than 90 days");
return false; //abort submission
}

Regards
Harish