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

Bhuvan
Kilo Patron

@SandeepKSingh 

 

Why do you need to give the option to user if you do not want any other value ?

 

Configure system dictionary for the field to use a default value with current date and use GlideDate function.

 

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

 

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

 

Thanks,

Bhuvan

@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

SandeepKSingh
Kilo Sage

Thanks for all Answer !!
can I get GlideDate and time all Details ?

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/

Thanks Buddy !!