Date Help !!

SandeepKSingh
Kilo Sage

How can you configure a form field so that, no matter what a user tries—whether picking yesterday, tomorrow, or even a year back—the only value the system stubbornly accepts is today’s date, straight from the system clock?

5 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @SandeepKSingh 

 

You can use a UI Policy to ensure that the entered date is today or a future date.
Set the condition accordingly and apply it on the same field.

If you want to add validation on the backend as well, you can include an error message using a UI Policy script.
Try it out — this approach should work for your use case.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

Ravi Gaurav
Giga Sage
Giga Sage

Hi @SandeepKSingh 

As suggested by @Dr Atul G- LNG  we can go with UI POLICY....
or you can write the below code:-

var gdt = new GlideDateTime();

var todayStr = gdt.getLocalDate().toString();

if (current.date_of_entry.toString() !== todayStr)

{

current.date_of_entry = todayStr;

gs.addErrorMessage('The date of entry must be the current date.'); current.setAbortAction(true);

}

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

GlideFather
Tera Patron

Hi @SandeepKSingh,

 

Wouldn't it be easier from a UX perspective to just make the field read-only and default it to today’s date?

 

If users can only select today and nothing else, giving them the option to edit the field feels a bit pointless.

Why let them change it if there's no real choice?

 

Create a variable and default value can be "javascript: new GlideDateTime();" and just make it read only..

 

GlideFather_0-1757340757490.png

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


View solution in original post

@SandeepKSingh 

 

Below is for reference,

Bhuvan_0-1757341036769.pngBhuvan_1-1757341056622.png

Sample dictionary entry,

Bhuvan_2-1757341337173.png

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

View solution in original post

Hi ..

The below Article will help !!

https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/...

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

12 REPLIES 12

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @SandeepKSingh 

 

You can use a UI Policy to ensure that the entered date is today or a future date.
Set the condition accordingly and apply it on the same field.

If you want to add validation on the backend as well, you can include an error message using a UI Policy script.
Try it out — this approach should work for your use case.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ravi Gaurav
Giga Sage
Giga Sage

Hi @SandeepKSingh 

As suggested by @Dr Atul G- LNG  we can go with UI POLICY....
or you can write the below code:-

var gdt = new GlideDateTime();

var todayStr = gdt.getLocalDate().toString();

if (current.date_of_entry.toString() !== todayStr)

{

current.date_of_entry = todayStr;

gs.addErrorMessage('The date of entry must be the current date.'); current.setAbortAction(true);

}

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

ifti122
Tera Guru

Hi @SandeepKSingh ,

Based on your requirement (“no matter what a user tries, the only value should be today’s date”), another simple approach is to just make the field read-only and auto-populate it with today’s system date on form load.

  • Use a UI Policy or an onLoad Client Script to set the field value to new GlideDateTime().getLocalDate().toString().

  • Mark the field read-only so users can’t modify it.

This way, you don’t need extra validation or error handling.

 

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.

GlideFather
Tera Patron

Hi @SandeepKSingh,

 

Wouldn't it be easier from a UX perspective to just make the field read-only and default it to today’s date?

 

If users can only select today and nothing else, giving them the option to edit the field feels a bit pointless.

Why let them change it if there's no real choice?

 

Create a variable and default value can be "javascript: new GlideDateTime();" and just make it read only..

 

GlideFather_0-1757340757490.png

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */