Scheduled Job: Run every three hours between 7am - 4pm

Muhammad Salar
Giga Sage

Hi All,

MuhammadSalar_0-1755024157941.png


I have a scheduled job that runs on Monday, Thursday, and Friday.
I also want to add this condition: run every three hours between 7 AM and 4 PM, while keeping the existing days functionality.

How to do that?


2 ACCEPTED SOLUTIONS

@Ankur Bawiskar 
Need to run every three hours between 7 AM and 4 PM, not after 4 PM
i used this logic for start-end time with starting time field empty
Is it ok or any suggestion to improve this logic?

var now = new Date();
var dayOfWeek = now.getDay();
var hour = now.getHours();
gs.info('hours '+hour);

var allowedDay = (dayOfWeek >= 1 && dayOfWeek <= 5);

// Only allow between 07:00 and 16:00
var allowedTimeRange = (hour >= 7 && hour < 16);

if(allowedDay && allowedTimeRange) {
answer = true;
}
else {
answer = false;
}

 

View solution in original post

@Muhammad Salar 

Nice catch, I forgot to have that.

yes you will have to ensure it stops at 4pm

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Muhammad Salar
Giga Sage

@Ankur Bawiskar can you please look into this?

Ankur Bawiskar
Tera Patron
Tera Patron

@Muhammad Salar 

for that you need to change like this

Run -> Periodically

Repeat Interval -> 3 hours

Starting Time -> 7 AM

Condition: Same script as above.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 
Need to run every three hours between 7 AM and 4 PM, not after 4 PM
i used this logic for start-end time with starting time field empty
Is it ok or any suggestion to improve this logic?

var now = new Date();
var dayOfWeek = now.getDay();
var hour = now.getHours();
gs.info('hours '+hour);

var allowedDay = (dayOfWeek >= 1 && dayOfWeek <= 5);

// Only allow between 07:00 and 16:00
var allowedTimeRange = (hour >= 7 && hour < 16);

if(allowedDay && allowedTimeRange) {
answer = true;
}
else {
answer = false;
}

 

@Muhammad Salar 

Nice catch, I forgot to have that.

yes you will have to ensure it stops at 4pm

If my response helped please mark it correct and close the thread so that it benefits future readers.

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