How to send a email twice in a day only on business days.

Pavan Kumar28
Tera Contributor
 
Hi all,
 
I have a requirement to send an email twice a day, only on business days (Monday to Friday). For this I created a periodical scheduled job, but I'm stuck with the conditions. The requirements are as follows:
 
1. Frequency: Twice daily on business days
Timing: 10:00 AM and 4:30 PM
 
2. Frequency: Every 2 hours on business days between 9:00 AM and 6:00 PM
Timing: 9:00 AM, 11:00 AM, 1:00 PM, 3:00 PM, 5:00 PM
 
Could anyone please help me with how to set up the conditions to meet these requirements?. Attaching the code which i added.

PavanKumar28_0-1718357913772.png

 


Code

var gr=new GlideRecord('change_request');
gr.addEncodedQuery('active=true^approval=requested');
gr.query();
while(gr.next())
{
    gs.eventQueue('cr.pending_approvals.alert', gr);
}
Thanks,
Pavan

 

1 REPLY 1

johnfeist
Mega Sage
Mega Sage

Hi Pavan,

 

Assuming that your notification is set up for table = change_request, you should be fine.  The simple way to run things twice daily is to set up two jobs.  To only run it on business days, add something like this to your script or create a condition:

var theDT = new GlideDateTime();
var theDTDay = theDT.getDayOfWeek();
if (theDTDay < 6) {
//add your existing code here
}

That will give you weekdays.  If you need to consider holidays, that gets a lot more complicated because you need to reference calendars and possibly other values depending if you are international, etc.

 

If you want to run everything from one job, just enhance the above script so that after determining the day of the week, you evaluate the current time and if it matches your timing for sending out notices execute your existing script.

 

Before setting this up, check that your calendars treat Monday as day 1.  If not, adjust the logic in the above script to conform.

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster