Email Notification due date Prior to 2 days excluding weekends

kks
Tera Contributor

Hi All,

Good evening to all.

I had a requirement to notify the problem manager prior to 2 days based on the due date. The below script of mine is working as expected.

My schedule job script below:

Script name : Problem Task Due date Reminder two days

queryPlannedDate();
function queryPlannedDate(){
var qrystr = "active=true^due_date>javascript:gs.daysAgoEnd(-1)^due_date<javascript:gs.daysAgoEnd(-2)"; 
var expdt = new GlideRecord('problem_task');


expdt.addEncodedQuery(qrystr);
expdt.query();

while(expdt.next()){

gs.eventQueue('problem_task.duedate1', expdt, expdt.assigned_to);
}

}

 

This script will execute on daily basis. It is working fine. Now the user tweaked the request and he wants exclude the week end(saturday and sunday). If the Problem task due is on Monday, The script should skip the saturday and sunday and fire on thursday( 2 days prior excluding weekends ). If the problem task due date is on Tuesday, This script will trigger on Friday.

Is there a way I can modify my script or any suggestions would be of great help because I have no clue on how to exclude weekends from the script.

Note : the above script is running based on al calendar days.

Thanks

Kamal

1 ACCEPTED SOLUTION

Kamal, You dont have to wait till friday to test if the logic skips the weekends. For example, you can increase the delay from 2 days to 4 days(or more than 4 days). So today is Tuesday August 21st, adding 4 days to today in your 24/5 schedule should give us Monday by skipping weekends. To increase the delay from 2 days to 4 or more days, just change the below paramters for the GlideDuration in the script(line 1) var dur = new GlideDuration('4 00:00:00'); This way you can check if weekends are getting skipped or not.

View solution in original post

15 REPLIES 15

TrenaFritsche
Tera Expert

Hello, I am looking to define a date that is 5 business days prior to today.  I tried using the solution using a 24 x 5 schedule, but cannot put a negative number in the Glide Duration.  It returns the current date time.  How can I subtract with this?  Or do I have to go about it differently?   Suggestions?

 

Thanks,

Trena