Copy this script into ServiceNow under application x_786686_hr_leave (Australia). Table/API names already use the current scope.
Source: src/client/client_scripts/CS1_validate_dates.js
/**
* Client Script: CS1 - Validate Dates
* Application: Custom · Scope: x_786686_hr_leave · sys_id: c84db0e8839f0b509f02b0d6feaad3c9
* Table: x_786686_hr_leave_req_v2
* Type: onChange
* Field: u_end_date
*
* Shows an error if end date is before start date.
*/
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') return;
var start = g_form.getValue('u_start_date');
var end = g_form.getValue('u_end_date');
if (!start || !end) return;
if (end < start) {
g_form.showFieldMsg('u_end_date', getMessage('End date cannot be before start date'), 'error');
g_form.clearValue('u_end_date');
} else {
g_form.hideFieldMsg('u_end_date', true);
}
}