- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi,
I have written onchange client script, below is my script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
if (newValue == oldValue)
return;
var format = g_user_date_time_format; // or g_user_date_format
var dateMs = getDateFromFormat(newValue, format);
var selectedDate = new Date(dateMs);
selectedDate.setHours(0,0,0,0);
var today = new Date();
today.setHours(0,0,0,0);
if (selectedDate < today) {
g_form.clearValue('due_date');
setTimeout(function() {
g_form.showFieldMsg(
'due_date',
'Past dates are not allowed. Please select Today or Future.',
'error'
);
}, 100);
} else {
g_form.hideFieldMsg('due_date');
}
}
Code is working fine in Native view, when I am working on SOW it is not working.
Field is due_date and Type is Date/Time
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
this UI policy worked for me in both
Even if you give 1 min in past it gives error
Output
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have created new UI Policy, It is working fine
I have query here:
I have entered Due Date as 16/02/2026 07:09:22, After saving this it is allowed me , working fine.
Now After 2 minutes if I come to same Problem record, it is showing error message.
what can I do here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Glad to know that my approach worked
uncheck the onLoad checkbox for your UI policy
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
57m ago
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @Sriram Pusuluri ,
The solution proposed by @Ankur Bawiskar looks better.
But for your script you mention, can you please verify if the UI Type of the script is set to "All"?
