- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 12:49 AM
Hi All,
I created two fields on the catalog item like start date and end date. Both fields should not allow to fill the past date and time. It only future date and time needs to allow.
Can anyone help to write the script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 01:42 AM
Have you tried to define an UI Policy to validate if the selected date before today, then clear the date and display the error message. Sample below
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 12:55 AM
In your onChange client script you could you the below code
g_form.setValue("date_field","");
g_form.showFieldMsg("date_field","Enter valid date ","error");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 12:57 AM
Hi @PRAGHATIESH S,
Whilst you can create a client script for this, it can be implemented a lot easier and faster using a Catalog UI Policy.
Here's a similar post and response I provided to another community member not so long ago. Take a look. (Please note, in the example I made it 24hrs in the future, you can simply make it 12 hour or 1 min in the future from the current time depending on your requirement).
Check the Response from Robbie post detailing how to implement the UI Policy: https://www.servicenow.com/community/developer-forum/date-variable-cannot-accept-past-date-and-needs...
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 01:42 AM
Have you tried to define an UI Policy to validate if the selected date before today, then clear the date and display the error message. Sample below
Cheers,
Tai Vu