- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 08:49 AM
I have a requirement to restrict a date field. This is for a Service Catalog Item. The variable is target_date. We need to set it up so that the target date selected cannot be in the past and needs to be 30 days or greater from the current date.
I have found some solutions on here but not are working.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 09:41 AM
That's mentioned in the article, something like this would give you a message:
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 09:41 AM
That's mentioned in the article, something like this would give you a message:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 10:04 AM
This worked like a charm! It's much better than using client scripts...
Someday when time permits, I will change all the client scripts over to a UI Policy - thanks for the information - I have bookmarked your article.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 09:19 AM
please try this; this worked for me.
Script Include: it should be client callable
var DateTimeAjax = Class.create();
DateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDate: function () {
var gdt = new GlideDateTime(this.getParameter('sysparm_date'));
var nowTime = new GlideDateTime();
if(gdt < nowTime)
return 'Date is in past';
else{
var dt = new GlideDateTime();
dt.addDaysUTC(30);
if(gdt < dt){
return 'Date is not after 30 days from current date';
}
}
return '';
},
type: 'DateTimeAjax'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = g_form.getValue('target_date'); //First Date/Time field
var ga = new GlideAjax('DateTimeAjax');
ga.addParam('sysparm_name', "checkDate");
ga.addParam('sysparm_date', cdt); //
ga.getXMLAnswer(function(answer){
if(answer != ''){
alert(answer); // remove this after testing
alert('The lead time to process this request is 5 days.' + '\n' + 'If this is an urgent request please contact the Service Desk for assistance escalating this request.');
g_form.clearValue('target_date');
}
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 09:29 AM
I tried this but it is allowing me to enter dates that are within 30 days from today..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 09:25 AM
And, please also vote for https://community.servicenow.com/community?id=view_idea&sysparm_idea_id=79e1d7b1db2c8c185ed4a851ca96...
... a product enhancement to allow date validations in client scripts.