How to check if start date in change is after today?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 04:11 AM
How to check if start date in change is after today?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 04:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 04:39 AM
Hi Khushboo,
If it is only a date field and you want to check something in client script then have onChange client script on that field i.e start date and have following script.
you can even show an alert if you want as mentioned in sample script below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var startDate = new Date(newValue);
if(startDate <= new Date()){
alert('this is a previous date');
}
else{
alert('this is an ahead date');
}
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
‎05-17-2017 04:54 AM
write a OnChange Client script for End date field with below script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var end = g_form.getValue("u_glide_date_time_2");
var start = g_form.getValue("u_glide_date_time_1");
// skip if start or end is blank
if (start == "" || end == "") {
return;
}
// get user's date time display format
var format = g_user_date_time_format;
var isEndBeforeStart = compareDates(start, format, end, format);
// 1 (true) if start is greater than end
// 0 if end is greater than start of if they are the same
// -1 if either of the dates is in an invalid format
if (isEndBeforeStart > 0) {
alert("End must be after start");
g_form.setValue('u_glide_date_time_2','');
return false;
}
}
Regards,
Bubuprasad