display banner message on change form when selecting the planned start date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
var BlackoutCheckAJAX = Class.create();
BlackoutCheckAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkBlackout: function() {
var date = this.getParameter('sysparm_date');
if (!date) {
return '';
}
var gr = new GlideRecord('cmn_schedule_blackout');
gr.addQuery('start_date_time', '<=', date);
gr.addQuery('end_date_time', '>=', date);
gr.query();
if (gr.next()) {
return gr.name.toString();
}
return '';
}
});
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('BlackoutCheckAJAX');
ga.addParam('sysparm_name', 'checkBlackout');
ga.addParam('sysparm_date', newValue);
ga.getXMLAnswer(function(response) {
g_form.clearMessages(); // clear old banners
if (response) {
g_form.addErrorMessage("The selected time falls within the " + response + " change peak restriction calendar.");
}
});
}
function onLoad() {
var plannedDate = g_form.getValue('planned_start_date');
if (plannedDate) {
var ga = new GlideAjax('BlackoutCheckAJAX');
ga.addParam('sysparm_name', 'checkBlackout');
ga.addParam('sysparm_date', plannedDate);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.addErrorMessage("The selected time falls within the " + response + " change peak restriction calendar.");
}
});
}
}
this is displaying incorrect blackout name when selecting planned date as 28-04-4026 it is displaying mother date blackout name,, but mother date blackout start date time - 09-05-2026 how to fix this so that it displays correct blackout schedule name when selecting the planned date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hello @satya1995,
var BlackoutCheckAJAX = Class.create();
BlackoutCheckAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkBlackout: function() {
var dateStr = this.getParameter('sysparm_date');
if (!dateStr) {
return '';
}
// Convert the input string to a GlideDateTime object to ensure
// correct format comparison (YYYY-MM-DD HH:MM:SS)
var gdt = new GlideDateTime();
gdt.setDisplayValue(dateStr);
var systemDate = gdt.getValue();
var gr = new GlideRecord('cmn_schedule_blackout');
gr.addQuery('start_date_time', '<=', systemDate);
gr.addQuery('end_date_time', '>=', systemDate);
// Ensure we don't pick up inactive or retired blackout records
gr.addActiveQuery();
// Order by start date so you get the most specific/recent match
gr.orderBy('start_date_time');
gr.query();
if (gr.next()) {
return gr.getValue('name');
}
return '';
},
type: 'BlackoutCheckAJAX'
});
Client Script (onChange):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('BlackoutCheckAJAX');
ga.addParam('sysparm_name', 'checkBlackout');
ga.addParam('sysparm_date', newValue);
ga.getXMLAnswer(function(response) {
g_form.clearMessages(); // Remove previous error banners
if (response) {
g_form.addErrorMessage("The selected time falls within the '" + response + "' change peak restriction calendar.");
}
});
}Client Script (onLoad):
function onLoad() {
var plannedDate = g_form.getValue('planned_start_date');
if (plannedDate) {
var ga = new GlideAjax('BlackoutCheckAJAX');
ga.addParam('sysparm_name', 'checkBlackout');
ga.addParam('sysparm_date', plannedDate);
ga.getXMLAnswer(function(response) {
if (response) {
// We don't clear messages here to avoid removing system notifications
g_form.addErrorMessage("The selected time falls within the '" + response + "' change peak restriction calendar.");
}
});
}
}
Thanks
SP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
so what debugging did you do?
what are your findings?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
