How to validate end time should be greater than start time in hh:mm? client script for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 12:03 PM
If the user chooses start time which is greater than the chosen end time then , message has to dispaly saying end time should be greater than start time in the client script
time is given in drop down as hh:mm for both start and end time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 12:33 AM
Hi
Once check this below link for reference
A Date field Should not allow Past Dates using Client Script in ServiceNow
If my response is helpful, then Please mark as Correct Answer/Helpful.
Please check and let us know.
Thanks 🙂
Shakeel Shaik.
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 12:47 AM
Hi
You can use this onChange script on the start date:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var end = g_form.getValue('due_date');
var start = g_form.getValue('u_planned_start_date');
var format = g_user_date_time_format;
var isEndBeforeStart = compareDates(start, format, end, format);
// skip if start and end is blank
if (start == "" && end == "") {
return;
}
// skip if start is not blank and end is blank
if (start != "" && end == ""){
return;
}
if (isEndBeforeStart) {
g_form.setValue('u_planned_start_date', '');
alert("Planned start date must be before Planned end date.");
}
}
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep