Send Email Periodically 1 Hour for specific Time

Muhammad Arif B
Tera Contributor

Hi, I have requirement to send email by using Scheduled Email Report every 1 hours but specifically between office hour 8AM until 8PM daily. Anyone can provide script or guidance on how to fulfill this requirement?

Thanks

MuhammadArifB_0-1768380817822.png

 

8 REPLIES 8

I have tested in our dev instance. it is working (sending every 1 hour between 8am - 8pm). But when apply the same script into actual scheduled email report at our production instance, it is not working (sending every 1 hour full day 24x7). 

Hi @Ankur Bawiskar 

 

I have update the script to

var gdt = new GlideDateTime();
var hour = gdt.getTime().getHourOfDayLocalTime();
answer = (hour >= 7 && hour < 20);

and now its working. Might related to timezone

Thanks for your help

@Muhammad Arif B 

Glad to know.

Please mark my earlier response with script as correct to close the thread.

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

Tejas Adhalrao
Tera Guru

Hi @Muhammad Arif B ,

 

TejasSN_LogicX_0-1768446177335.png

 check here ->  https://www.servicenow.com/docs/bundle/zurich-now-intelligence/page/use/reporting/task/t_ScheduleARe...

 

script :-

 

// Get current system time and convert to local display string
var now = new GlideDateTime();
var displayTime = now.getDisplayValue(); 

// Use substring to grab the two-digit hour directly from 'YYYY-MM-DD HH:mm:ss'
// The hour starts at character index 11
var hour = parseInt(displayTime.substring(11, 13), 10);

// Set answer to true only if the hour is between 8 (8 AM) and 19 (7:59 PM)
if (hour >= 8 && hour < 20) {
    answer = true;
} else {
    answer = false;
}