Set error message if the start date is greater than end date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 11:41 PM
Set error message if the start date is greater than end date.Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 05:44 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 12:38 AM
@Shaik
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 12:17 AM
HI
Create an onChange script for your start_date and end_date fields.
//start_date onChange Function
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var nowDate = new Date(); //Creates a JS date object for right now
var checkStart = new Date(newValue); // Create a JS Date object using the desired start_date field (from newValue parameter)
if (nowDate >= checkStart){ //JS Date objects compared
alert('You cannot select today or a day in the past');
g_form.setValue('start_date','');
}
}
//end_date onChange Function
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var startDate = new Date(g_form.getValue('start_date')); //get the value of the start_date field using the g_form.getValue method
var checkEnd = new Date(newValue); // create a new JS date from the desired end_date field (using newValue parameter)
if (checkEnd <= startDate){ //Again - a simple JS Date object comparison
alert('End date must be after start date');
g_form.setValue('end_date','');
}
}
Please mark reply as Helpful/Correct, if applicable. Thanks!