- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 07:24 AM - edited 06-10-2025 07:25 AM
Hi Community,
I have a requirement where I have a date and time field (DD:MM:YYY HH:MM:SS) so I need to add validation to it in such a way that even the time should not be in the previous minute cause I am able to achieve validation on the date such that its not a previous date but if I select todays date but two hours ago it lets me select it where as it should not work like that it should clear the value on that field. As well as the showFieldMsg is not working its not showing the info message like "The selected date cannot be in the past".
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 08:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 08:20 AM
approach shared by @J Siva should work fine.
In case you want onChange client script then use this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('u_datetime_field');
var selectedDateTime = new Date(getDateFromFormat(newValue, g_user_date_time_format)).getTime();
var nowTime = new Date().getTime();
if (nowTime > selectedDateTime) {
g_form.showFieldMsg('u_datetime_field', 'The selected date cannot be in the past', 'error');
}
}
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