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

Hello Scott,

Can you please provide your input on my ask?

I am still awaiting your response.

 

Thanks

Ian Mildon
Tera Guru

Place the following in the conditional script field and set the schedule to run daily

(function() {  
      //run on weekdays only  
      var day = new Date().getDay();  
      return (day != 6 && day != 7);
    })();

Hello Ian,

So you mean to say there is no need of adding any schedule name in the script right?

So I will define the script as shared by you.

(function() {  
      //run on weekdays only  
      var day = new Date().getDay();  
      return (day != 6 && day != 7);
    })();

Will it work for me?

 

Thanks

Correct, with this conditional script you do not need to use a system schedule.

On the scheduled job, select the "conditional" box and pop the script in the script box. Then set the scheduled job to run daily at the time you want.

Then just populate the rest of the scheduled job with what you are wanting it to do; which would be to run your script.

Hello Ian,

I have added the required condition in the Condition box but it didn't satisfy the condition.

The Scheduled Job has run on Sunday which is not expected.

 

Thanks