Autofill CAB Date – When a NORMAL Change Moves to the approval state AND "CAB Required" is set to TRUE, set a CAB date in the "CAB date" (cab_date) field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 07:01 AM
Hi Team,
I have a requirement to set Cab Date field when planned start is at least 36 hours prior to current week's CAB Date (Wednesday date at 8:00 AM CST) set the "CAB date" (cab_date) field to the current week's CAB date. IF the Planned Start time is less than 36 hours of current week's CAB date, move CAB Date to the following week.
CAB meetings (dates) are hosted weekly on Wednesday at 8 AM CST
EXAMPLE:
A CAB Meeting scheduled for Wednesday, 5/4/2022 @ 8 AM CST as of this moment (5/2/2022 @ 5:39).
If a Change request's Planned Start Date is scheduled 36 hours or more before Wednesday, 5/4/2022 @ 8 AM CST then the CAB date is Wednesday, 5/4/2022 @ 8 AM CST.
Else, if the change request's Planned Start Date is scheduled less than 36 hours before Wednesday, 5/4/2022 @ 8 AM CST then the CAB date is Wednesday, 5/11/2022 @ 8 AM CST
Can i get help on this.
Thanks,
Apoorva Deshpande.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 07:33 AM
I did something similar, except in our case the cutoff day/time is noon on Monday. Here is the on "insert" Business Rule I am using for this:
function checkDeadline(){
var gdt = new GlideDateTime();
var dayOfWeek = gdt.getDayOfWeekLocalTime(); // Monday = 1
var nowHour = gdt.getLocalTime(); // noon = 12:00:00
//Create the html contents of the information message
var link = '<a href="change_request.do?sys_id=' + current.sys_id + '" class="breadcrumb" >' + current.number + '</a>';
var message1 = 'Change Request ' + link + ' will be submitted to this weeks CAB meeting.';
var message2 = 'Change Request ' + link + ' will be submitted to next weeks CAB meeting.';
//set the CAB date
var cabDate = new GlideDateTime();
var now = new GlideDateTime();
if(dayOfWeek == '6' || dayOfWeek == '7' || dayOfWeek == '1' && nowHour <= '1970-01-01 12:00:00'){ //allow all day on weekends
cabDate.setValue(now.getInternalMidnight(2)); //sets the cabDate to midnight on tuesday (UTC!!!)
cabDate.addSeconds(18000); //modify to 5 hours to push us past midnight local time
current.u_cab_date = cabDate.getValue();
gs.addInfoMessage(message1);
_setCabTime();
} else {
cabDate.setValue(now.getInternalMidnight(2)); //sets the cabDate to midnight on tuesday (UTC!!!)
cabDate.addSeconds(18000); //modify to 5 hours to push us past midnight local time
cabDate.addWeeks(1); //addWeeksLocaltime(1)
current.u_cab_date = cabDate.getValue();
gs.addInfoMessage(message2);
_setCabTime();
}
}
function _setCabTime(){ //set time to 14:30:00
var getDate = new GlideDateTime(current.u_cab_date);
var arrDate = [];
arrDate = getDate.toString().split(' ');
current.u_cab_date.setDisplayValue(arrDate[0]+ ' 14:30:00','yyyy-MM-dd HH:mm:ss');
}
checkDeadline();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 07:39 AM
I deleted my previous answer as I realized you wanted this to be specifically for the Planned Start date entry. Here is my script for doing so; based on a cutoff day/time of midnight on Monday. This would be set to run on insert and update as it will recalculate and update the date/time:
function checkDeadline(){
var gdt = new GlideDateTime(current.start_date); //planned start time
var dayOfWeek = gdt.getDayOfWeekLocalTime(); // Monday = 1
var nowHour = gdt.getLocalTime(); // noon = 12:00:00
//set the CAB date
var cabDate = new GlideDateTime();
var midNight = gdt.getInternalMidnight(2); //midnight on Tuesday
if(dayOfWeek == '6' || dayOfWeek == '7' || dayOfWeek == '1' && nowHour <= '1970-01-01 23:59:59'){
cabDate.setDayOfWeek(2); //sets the cabDate to Tuesday
cabDate.setValue(midNight); //want to set the next Tuesday from start_date in UTC
cabDate.addSeconds(18000); //modify to 5 hours to push us past midnight local time
current.u_cab_date = cabDate.getValue(); //generate the CAB Date
_setCabTime();
_recalculateDates();
} else {
cabDate.setDayOfWeek(2); //sets the cabDate to Tuesday
cabDate.setValue(midNight); //want to set the next Tuesday from start_date in UTC
cabDate.addSeconds(18000); //modify to 5 hours to push us past midnight local time
cabDate.addWeeks(1); //addWeeksLocaltime(1)
current.u_cab_date = cabDate.getValue(); //generate CAB Date +1 week
gdt.addWeeks(1); //add 1 week to planned start
current.start_date = gdt.getValue(); //generate Start Date +1 week
_setCabTime();
_recalculateDates();
}
}
function _setCabTime(){ //set time to 11:00:00
var getDate = new GlideDateTime(current.u_cab_date);
var arrDate = [];
arrDate = getDate.toString().split(' ');
current.u_cab_date.setDisplayValue(arrDate[0]+ ' 11:00:00','yyyy-MM-dd HH:mm:ss');
}
function _recalculateDates(){ //date validations
var startDate = new GlideDateTime(current.start_date);
var cabVal = new GlideDateTime(current.u_cab_date);
var rightNow = new GlideDateTime();
if(cabVal.before(rightNow)) {
gs.addErrorMessage("The CAB Meeting date cannot be in the past. Please set a new (future) Planned Start time.");
current.start_date.setError('Please reset this to a future date and time');
current.u_cab_date.setError('The Cab Meeting will automatically update based on the Planned start correction');
current.setAbortAction(true);
}
if(startDate.before(rightNow)) {
gs.addInfoMessage("The Planned Start date cannot be in the past; recalculating...");
cabVal.addDaysLocalTime(1);
current.start_date = cabVal.getValue(); //Cab Date +1 day
}
if(startDate.before(cabVal)) {
gs.addInfoMessage("The Planned Start date cannot be before the CAB Date; recalculating...");
cabVal.addDaysLocalTime(1);
current.start_date = cabVal.getValue(); //Cab Date +1 day
}
else {
return;
}
}
checkDeadline();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 08:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2022 06:12 AM
Did you just copy/paste the script as is? Or did you then update the field values to match your instance?
"u_cab_date" is a custom field, so all references to it will need to be updated to whatever the field is on your instance.
Beyond that, the only difference I see is you are running these at 100. I have mine set to 10 so they running sooner in the processing order.