Restrict the submission of Normal and Standard change requests with a past date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 03:07 AM
Hello Team,
We have requirement "Restrict the submission of Normal and Standard change requests with a past date"
I have created below script but it's not working. Please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 03:29 AM
use this
function onSubmit() {
var changeType = g_form.getValue('type');
var requestedStartDate = g_form.getValue('start_date');
if ((changeType == 'Normal' || changeType == 'Standard') && requestedStartDate) {
var today = new Date().getTime();
var selectedDate = new Date(requestedStartDate).getTime();
if (today > selectedDate) {
g_form.showFieldMsg('start_date', 'The requested start date cannot be in the past.', 'error');
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 03:50 AM
Hello Ankur Bawiskar,
Thank you for Response!!
It's not working still allow me to submit the past date.
Regards,
Raju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 04:06 AM
Ankur's answer will work for you; just replace Normal with normal and Standard with standard. If you want an error message instead of field message, you can use
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 04:17 AM
I hope you are using the correct choice values for normal and standard
if ((changeType == 'normal' || changeType == 'standard') && requestedStartDate) {
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