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-15-2022 01:28 AM
Hi,
I have changed Field name to cab_required and pasted but i can not see time or correct Date format i.e, to populate as per my condition.
Can you Send your instance Cab Date Field snap. I want to see Cab Date format along with Planned Start and Planned End.
Thanks,
Apoorva Deshpande.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 05:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 04:49 AM
Hi Ian Mildon,
I tried this script but it is not populating Time in Cab Date field and if i set Planned Start Date as Sunday, Cab Date is setting to next Wednesday which should set to Following Wednesday. Could you please tell where i am going wrong.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
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(3); //midnight on Wednesday
//changing as per requirement
if(current.type=='normal' && current.cab_required == true && current.state == 6)
{
//if(dayOfWeek == '1' || dayOfWeek == '2' && nowHour <= '1970-01-01 23:59:59'){
if(dayOfWeek =='1' || dayOfWeek =='2' && nowHour >= '1970-01-01 19:59:59' ){
// 19:59:59 to set Next wednesday if time is above 8pm
cabDate.setDayOfWeek(3); //sets the cabDate to Wednesday
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);
current.cab_date = cabDate.getValue(); //generate the CAB Date
_setCabTime();
}
else{
cabDate.setDayOfWeek(3); //sets the cabDate to Wednesday
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.cab_date = cabDate.getValue(); //generate CAB Date +1 week
_setCabTime();
}
}//}
else{
current.cab_date='';
}}
function _setCabTime(){ //set time to 11:00:00
var getDate = new GlideDateTime(current.cab_date);
var arrDate = [];
arrDate = getDate.toString().split(' ');
current.cab_date.setDisplayValue(arrDate[0]+'08:00:00','yyyy-MM-dd HH:mm:ss');
}
checkDeadline();
})(current, previous);
Thanks,
Apoorva Deshpande.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 09:20 AM
I'll check through your version.
One thing that I did spot that needs changing is the line "current.cab_date.setDisplayValue(arrDate[0]+'08:00:00','yyyy-MM-dd HH:mm:ss');"
You need to insert a space in front of the time value so it would be
current.cab_date.setDisplayValue(arrDate[0]+' 08:00:00','yyyy-MM-dd HH:mm:ss');