Regarding onchange planned start date Validation in change Request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 07:31 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}var changeType = gForm.getValue('type');
if (changeType.toLowerCase() === 'normal') {
var ga = new GlideAjax('ValidateStartDateUtils');
ga.addParam('sysparm_name', 'isFutureDateTime');
ga.addParam('sysparm_selected_date', newValue);
ga.getXMLAnswer(function(response) {
if (response === 'false') {
gForm.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');
gForm.setValue('start_date', '');
}
});
}
}this is client script
var ValidateStartDateUtils = Class.create();
ValidateStartDateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isFutureDateTime: function() {
var selectedDate = this.getParameter('sysparm_selected_date');
if (!selectedDate) return false;
var selected = new GlideDateTime(selectedDate);
var now = new GlideDateTime();
return selected.after(now) ? 'true' : 'false';
}
});and script includes but it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:25 AM
I just edited my response above, can you have a look and let me know if you still see issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 08:43 AM
this should work for you without GlideAjax and Script Include
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var changeType = g_form.getValue('type');
if (changeType.toLowerCase() == 'normal') {
var date = new Date();
var dateEntered = new Date(getDateFromFormat(newValue, g_user_date_time_format));
if (dateEntered < date) {
g_form.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');
g_form.clearValue('start_date');
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-13-2025 08:17 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-20-2025 02:12 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-20-2025 04:14 AM
Hello Ankur,
It's working fine but just clear the value of today date and today before date only. Developers should understand this but to understanding the non IT people i need to get one alert message for understanding purpose.
Regards,
D Manohar Reddy.