Restrict Incident Date Selection ONE MONTH AGO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12 hours ago
I have created a record producer with a variable called Incident Date, and I need to restrict users from selecting a date that is more than one month old.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
you can write onChange client script and validate like this
Note: I assume 1 month is 30 days
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('fielName');
var selectedDate = new Date(newValue);
var todayDate = new Date(); // Now
todayDate.setDate(todayDate.getDate() + 30);
if (selectedDate.getTime() < todayDate.getTime()) {
g_form.showFieldMsg('fieldName', 'Please select valid date', '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
9 hours ago
Thank you for marking my response as helpful.
💡 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
10 hours ago
HI @may13 ,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var selectedDate = new Date(getDateFromFormat(newValue, g_user_date_format));
var currentDate = new Date();
currentDate.setMonth(currentDate.getMonth() - 1);
currentDate.setDate(currentDate.getDate() - 1);
if (selectedDate.valueOf() >= currentDate.valueOf()) {
alert('please select on month old date');
//write your additional code here to clear the value or whatever d action dat you want to take
}
}create a onChange catalog client script on the record producer on the incident date variable with above script
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
