Verifying start and end dates in change requests
If you are seeing incorrect start and end dates on change requests — for example, users are able to submit or modify a request with a Planned start date later than the Planned end date without a warning message - you can implement a custom script that verifies the start and end dates before you enter the time warp:
A date validation script for the start- and end-date fields can be set to trigger on the change request record. This script will check the start date against the current date, and display an error message if the start date is before the current date. It will also check the end date against the start date, and also display an error message if the end date is before the current date.
To verify these dates on a change request, one way is to create a business rule before insert or update:
- For example: Condition = current.start_date.changes() || current.end_date.changes() || current.work_start.changes() || current.work_end.changes())
- Use this script:
if (!current.end_date.nil() && !current.start_date.nil()) {if (current.end_date.getGlideObject().getNumericValue() <=current.start_date.getGlideObject().getNumericValue() ) {gs.addErrorMessage('Planned start must be before Planned end');current.start_date.setError('Planned start must be before Planned end');current.setAbortAction(true);}}if (!current.work_start.nil() && !current.work_end.nil()) {if (current.work_end.getGlideObject().getNumericValue() <=current.work_start.getGlideObject().getNumericValue() ) {gs.addErrorMessage('Actual start must be before Actual end');current.work_start.setError('Actual start must be before Actual end');
current.setAbortAction(true);
}
}
https://www.servicenow.com/community/in-other-news/verifying-start-and-end-dates-in-change-requests/ba-p/2265937