Date and time validation/ start date and end date validation.

Harish8
Kilo Contributor

i have two fields named as start date and end date, both are of date and time fields.I want to make validation on start date it should not be previous date and end date should be on start date. and start date time must be less than end date time .

i have performed the functionality through ui policies but it still taking end date to tomorrow date!

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

To make your search easier, I've copied the images from the article.

Again, no need for client script, glide ajax, etc.. There's just no valid reason for doing this.

image

image

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

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

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Because you mention date/time field, this should be achievable with (Catalog) UI Policy. Have a look at an article I wrote on this:
No Code date validations thru (Catalog) UI Policies
The article also contains a detailed example of comparing two fields with each other.

You do mention you tried already something, which is not working. Can you share anything?

Absolute NO reason to script this with client script, glideajax, etc..

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

hi Harish

try this:

You can use the Onchange Client and Script Include as below

 

Onchnage Client Script:

var ga = new GlideAjax('BlackoutDateValid');

ga.addParam('sysparm_name', 'EndDate');

ga.addParam('sysparm_startDate', g_form.getValue('upb_start_date'));

ga.addParam('sysparm_endDate', g_form.getValue('upb_end_date'));

ga.getXMLAnswer(validateEndDate);

}

}

function validateEndDate(answer){

if(answer == 1 || answer == '1'){

alert('Blackout End Date should be greater or equal to Blackout Start Date');

g_form.clearValue('upb_end_date');

}

}

 

Script Include:

EndDate : function(){

var _startDate = new GlideDateTime(this.getParameter('sysparm_startDate'));

var _endDate = new GlideDateTime(this.getParameter('sysparm_endDate'));

return _startDate.compareTo(_endDate);

}

___________________________________________________________

if for more detail refer the following thread (blog) it help you.

https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad

 

If it help mark helpful or correct 

Thanks and regards

Anil

Subhojit Das
Kilo Guru

Hi Harish,

Please, check the below screenshots.

Replace create date with start date.

If you find the content useful, please mark as Correct and Helpful.

Regards,

Subhojit Das

client side code is not working.