Normal chnage need to abort during the black schedule time, please help in the requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 06:16 AM
I have created a before insert business rule on change table, please correct this, black out schedule screen shot in below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 09:09 AM
Hi Arjun,
Why not use OOB functionality for this? Please see:
Activate the related plugins if not present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 03:04 PM
as mentioned in the screen shoot i have created back out schedule, but it not aborting the creation , for that i have written a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 03:23 PM
Hi try the following changes to your script. I've removed some 'gs.addInfoMessage' and updated some with useful information
(function executeRule(current, previous /*null when async*/) {
// Get the start and end dates of the new change request
var changeStartDate = current.start_date.getGlideObject().getDateTimeValue();
var changeEndDate = current.end_date.getGlideObject().getDateTimeValue();
gs.addInfoMessage('Start: ' + changeStartDate + ', End: ' + changeEndDate);
// Query for the specified blackout schedule
var blackoutQuery = new GlideRecord('cmn_schedule_span');
blackoutQuery.addQuery('schedule', 'a67892cd4720311073441288c26d43af');
blackoutQuery.query();
gs.addInfoMessage('Found: ' + blackoutQuery.getRowCount() + ' records');
if (blackoutQuery.next()) {
// Get the start and end dates of the blackout schedule
var blackoutStartDate = blackoutQuery.start_date_time.getGlideObject().getDateTimeValue();
var blackoutEndDate = blackoutQuery.end_date_time.getGlideObject().getDateTimeValue();
gs.addInfoMessage('Blackout start: ' + blackoutStartDate + ', End: ' + blackoutEndDate);
// Check if the change request's dates overlap with the blackout schedule
if (changeStartDate < blackoutEndDate && changeEndDate > blackoutStartDate) {
gs.addErrorMessage('Change request creation is not allowed during the specified blackout schedule.');
current.setAbortAction(true);
}
}
})(current, previous);
that should help you debug your logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 07:03 AM
Testing your setting of the vairables you used show each are 'undefined'. Try the following:
(function executeRule(current, previous /*null when async*/) {
// Get the start and end dates of the new change request
// var changeStartDate = current.start_date.getGlideObject().getDateTimeValue();
// var changeEndDate = current.end_date.getGlideObject().getDateTimeValue();
var changeStartDate = current.start_date;
var changeEndDate = current.end_date;
gs.addInfoMessage('Start: ' + changeStartDate + ', End: ' + changeEndDate);
// Query for the specified blackout schedule
var blackoutQuery = new GlideRecord('cmn_schedule_span');
blackoutQuery.addQuery('schedule', 'a67892cd4720311073441288c26d43af');
blackoutQuery.query();
gs.addInfoMessage('Found: ' + blackoutQuery.getRowCount() + ' records');
if (blackoutQuery.next()) {
// Get the start and end dates of the blackout schedule
// var blackoutStartDate = blackoutQuery.start_date_time.getGlideObject().getDateTimeValue();
// var blackoutEndDate = blackoutQuery.end_date_time.getGlideObject().getDateTimeValue();
var blackoutStartDate = blackoutQuery.start_date_time;
var blackoutEndDate = blackoutQuery.end_date_time;
gs.addInfoMessage('Blackout start: ' + blackoutStartDate + ', End: ' + blackoutEndDate);
// Check if the change request's dates overlap with the blackout schedule
if (changeStartDate < blackoutEndDate && changeEndDate > blackoutStartDate) {
gs.addErrorMessage('Change request creation is not allowed during the specified blackout schedule.');
current.setAbortAction(true);
}
}
})(current, previous);
And even the corrections are not needed, you can just use 'current.start_date', 'current.end_date', 'blackoutQuery.start_date_time', and 'blackoutQuery.end_date_time' in the "if" statement. You also need logic for either current.start_date or current.end_date falls withing the Blackout schedule.