Run the scheduled job only on weekdays except Sat and Sun

SNOW46
Tera Contributor

Hello All,

I have a requirement that when Incident Status is changed to On Hold, then On Hold Reason will open were Assigned to User needs to select as Enhancement option from the drop-down menu and the SLA will get Paused.

Once the user selects the Enhancement option, then a new Date/Time field will open below the On hold Reason field.

When the Assigned to user selects any particular Date and Time so till that duration or date/time the Incident will remain as On Hold and once the duration is completed or the Date is crossed, then the Status should automatically be changed to In Progress and at the same time a notification should trigger to the Assigned to User stating the Incident Status has been changed to In Progress now.

We have defined a Scheduled Job script for the same but it should not run on Sat and Sun as we have the SLAs running for different teams. I have tested some of the Incidents where I found that the scheduled job has run on weekends and the SLA stage changed from Pause to In Progress.

find_real_file.png

find_real_file.png

 

//var now = new GlideDateTime();
var inc = new GlideRecord('incident');
inc.addEncodedQuery('u_hold_reason=9^u_conditional_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORu_conditional_date<=javascript:gs.endOfToday()');
inc.query();
// gs.log('xyz : Enhancement');
while (inc.next()) {
     gs.eventQueue('conditionalholdtime',inc,'','');  
    gs.log('xyz: past or now time');
        inc.state = '2';
        inc.update();
}

 

Can someone help me on this to make this not run on weekends that are on Sat and Sunday to make sure that SLA is not getting to In Progress as I have a call with customer for the demo on Wednesday?

 

Thanks

12 REPLIES 12

scott barnard1
Kilo Sage

Hi In the scheduled job you can specify a condition. If that condition returns true the job runs if false it does not run.

 

You then have a schedule that you query. You can use blackout schedules or a specific schedule.

then you can use isInSchedule() to query if a date/time object is in that schedule.

Note if you are using a open time schedule then you would reverse the logic etc

 

function answercon(){
//Return 'true' to run the job
var answer = false;
//Find the schedule
schedRec.get('name','Name_of_schedule');
//Get the sys id for schedule
//var schedule = new GlideSchedule(schedRec.sys_id);
var schedule = new GlideSchedule(schedRec.sys_id,'UTC');
//Get current date and time
var date = gs.nowDateTime();
//Check current date and time is in schedule
  if (schedule.isInSchedule(date,"UTC")){
    answer = false;	
  } else {
    answer = true;
  }
  
return answer;
}

answercon();

 

 

 

Hi Scott,

You mean to say I need to define some schedules for the same. I just need to confirm that the scheduled job should not run on weekends.

function answercon(){
//Return 'true' to run the job
var answer = false;
//Find the schedule
schedRec.get('name','Name_of_schedule');
//Get the sys id for schedule
//var schedule = new GlideSchedule(schedRec.sys_id);
var schedule = new GlideSchedule(schedRec.sys_id,'UTC');
//Get current date and time
var date = gs.nowDateTime();
//Check current date and time is in schedule
  if (schedule.isInSchedule(date,"UTC")){
    answer = false;    
  } else {
    answer = true;
  }
  
return answer;
}

answercon();

Thanks

Hi Scott,

We have different schedules defined for the SLAs as below.

find_real_file.png

Thanks

Hello Scott,

Can you please help me out in reforming the script as I have attached the various schedules configured and those are used in various SLAs.

I need your help in the script shared by you as I have to configure the same in our Dev Instance and showcase it to the customer for demo.

 

Thanks