Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Date cannot be current date or Past

nameisnani
Mega Sage

Hi Team ,

 

There is Date Field in catalog form , attached screenshot . 

 

If users enters current date or past date it shouldn't take and it show an error . 

 

How to achieve this requirement .

 

nameisnani_0-1692756913096.png

 

I have tried with UI Policy , 

nameisnani_1-1692757268681.pngnameisnani_2-1692757288254.png

 

For this UI Policy output will be 

nameisnani_3-1692757337315.png

 

my requirement is 

 

If users enters current date or past date it shouldn't take and it show an error .

 

Thanks

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @nameisnani,

 

Your condition should be as below.

 

Condition:

Date_field is ATORBEFORE Today

 

Execute if true:

function onCondition() {
g_form.clearValue("Date_field");
g_form.showFieldMsg("Date_field", "Current date or past date not allowed" , "error");
}

 

For reference: No Code date validations through (Catalog) UI Policies 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

3 REPLIES 3

Sagar Pagar
Tera Patron

Hi @nameisnani,

 

Your condition should be as below.

 

Condition:

Date_field is ATORBEFORE Today

 

Execute if true:

function onCondition() {
g_form.clearValue("Date_field");
g_form.showFieldMsg("Date_field", "Current date or past date not allowed" , "error");
}

 

For reference: No Code date validations through (Catalog) UI Policies 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Harish Bainsla
Kilo Patron
Kilo Patron

function onLoad() {

var dateField = g_form.getValue('date_field');
var currentDate = new Date();

dateField.observe('change', function () {
var selectedDate = g_form.getValue('date_field');
if (selectedDate) {
if (new Date(selectedDate) <= currentDate) {
alert("Please select a future date.");
g_form.setValue('date_field', '');
}
}
});
}

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Have a look at this article which I wrote 4 years ago. Still valid!

- 2019-08-12 - Article - No Code date validations thru (Catalog) UI Policies

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn