Service catalog Date validation

ragz
Tera Expert

Hi ,

I am looking fro Date validation in service catalog date fields .

1) Start Date must be greater than TODAY .

2 End Date must be greater than Start Date .

I am using the below code but it is not working and giving zero for startDateMs and endDateMs all the time even though the date value is valid all the time .

var startDate = g_form.getValue("from_date");
var endDate = g_form.getValue("to_date");
var format = g_user_date_time_format;
var startDateMs = getDateFromFormat(startDate, format);
 alert(startDateMs);
var endDateMs = getDateFromFormat(endDate, format);
alert(endDateMs);
if(endDateMs <= startDate){
alert(g_form.getValue('from_date')+' '+g_form.getValue('to_date'));
alert('End date must be after Start date.');
}

How to fix this ? Thanks in advance !

1 ACCEPTED SOLUTION

That's correct, it's only a validation on the onChange. You could clear the date field.

Else you have to implement a check onSubmit.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

7 REPLIES 7

That's correct, it's only a validation on the onChange. You could clear the date field.

Else you have to implement a check onSubmit.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Yes thats the normal thing na , so you should clear the value on that as below 

find_real_file.png

 

Hope this helps

 

Mark the response as correct/helpful if that really helps

 

Thanks,

Siva

vishal_8_shah
Mega Expert

this script only works one time and then it allows to choose a day in past on the Service Portal. For some reasons it does not validate second and further changes on Service Portal.

 

Did anyone managed to resolve this?

 

Thank you.