- 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
why not use UI policy with no script and it will work in both sides?
💡 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
try this if you want to use script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
g_form.hideFieldMsg('due_date');
var today = new Date().getTime();
var selectedDate = new Date(newValue).getTime();
if (today > selectedDate) {
g_form.showFieldMsg(
'due_date',
'Past dates are not allowed. Please select Today or Future.',
'error'
);
}
}
💡 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 - last edited yesterday
- 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
