How to restrict the past dates selection on date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 01:32 AM
Hi all,
I need to restrict the past dates selection on the date field (Start_date). Fo this I created a Ui policy in when to apply I gave condition as Start_date before Today. In the scripting I have added a error message it's working fine but...if I open any existing cases in system that is already having the value of start_date it is showing up the error message on the case for the Active and Inactive cases also.
What is the solution so that the pop should show up only for Active cases where the start_date value is empty.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 01:42 AM
Hi @poornima batchu ,
Here is the Sample Script, please change to fit your requirement:
Script Include:
Name:DateValidation
Client callable: Checked
var DateValidation = Class.create();
DateValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateDate: function() {
var ActualEndDate = this.getParameter('sysparm_end_date');
return gs.dateDiff(gs.now(),ActualEndDate, true)/86400;
},
type: 'DateValidation'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('DateValidation');
ga.addParam('sysparm_name','validateDate');
ga.addParam('sysparm_end_date',g_form.getValue('u_business_need_by_date'));//give your date field
ga.getXML(ProcessResult);
function ProcessResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer < 0)
{
g_form.clearValue('u_business_need_by_date'); //give your date field
alert('Business need date should not be in the Past.');
}
}
}
Also, watch this video : https://www.youtube.com/watch?v=gghIdFlxsDg

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 01:58 AM
Hi there,
Please share details of what you tried and what is not working.
Kind regards,
Mark
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-06-2023 03:02 AM
In ui policy I tried this but this error message should not show up for the existing cases in the system where the date value is already given

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2023 03:36 AM
And what if you change the onLoad checkbox?
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field