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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kamal,

You need to use schedule in this calculation and determine when it should trigger.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

I have created Scheduled 24-5 weekdays excluding holidays.

PLease find the attachment.find_real_file.png

What should I update in my existing script ?.. To call this schedule

Please Suggest me.

Hi Kamal,

Iterate over every record and use Duration calculator. take due date from record and using duration calculator add 2 days. if it is today then trigger email

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Still I am not getting ankur. Please explain me and help me what should I right in my script?

to call the schedules?

 

Thanks,

Kamal