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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You could use Catalog UI Policies to do the date validation for you. Only in the script of the Catalog UI Policy low-code is needed, like giving the error message and maybe clearing the field.

Have a look at that instead of Catalog Client Script.

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

With applying a UI Policy that performs the date validation, the scripting part in the script field could be limited to something like:

g_form.addErrorMessage(getMessage('End date must be after Start date'));
g_form.clearValue('to_date');

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

siva_
Giga Guru

find_real_file.png

 

\System wil take of date formatting , no need of any validations for handling the date formats so. 

find_real_file.png

Hope this helps 

 

Thanks,

Sva

after I use the above UI Policy When submit it is allowing me to Submit . How to restrict user not to submit .

Need to add script ?