- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 12:46 AM
Hello all,
I have created a date and time field and the selected date and time should be one-hour in advance.
So, I have created a on Submit client script and it's not working.
Can someone help me please?
Regards,
Lucky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 01:08 AM
why not use UI policy?
Something like this and use Script field
My current time is approx 1:06:00 AM so it gave me error when I selected time within 60mins (1hour)
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 12:54 AM
Hi @Lucky1
GlideDateTIme is a server side script and not client side. You need to modify it in a script include or BR and send it here. You can only perform some basic modifications in the client side, like changing the formats.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 01:08 AM
why not use UI policy?
Something like this and use Script field
My current time is approx 1:06:00 AM so it gave me error when I selected time within 60mins (1hour)
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 02:48 AM
but this method is not working in esc portal view it is only working only in record producer try button view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 01:30 AM
If you still want to use onSubmit then update your script as this
function onSubmit() {
var mydate = g_form.getValue('date_and_time');
var minutes = 60;
var dt = new Date(getDateFromFormat(mydate, g_user_date_time_format)).getTime() + minutes * 60000; // add 60mins to date and then compare
var nowTime = new Date().getTime();
if (dt < nowTime) {
alert('date should be after 60 from now');
return false;
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader