- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
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..
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Below is for reference,
Sample dictionary entry,
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
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..
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */