Trying to create a Scheduled job which creates a Request every weekday

prudhvig
Tera Expert

Hi,

I have a requirement to write a scheduled job which runs every weekday.

I have developed a catalog item which looks as follows:

Screenshot (686).png

Screenshot (687).png

When I fill this catalog item, it automatically creates a Request, RITM and Catalog Task.

So now, this catalog item should be ordered automatically every weekday so that it finally creates a Request, RITM and Catalog Task.

I am very new to Servicenow and unable to think of how to solve this. Please help.

Thanks in advance.

1 ACCEPTED SOLUTION

Run:onDemand


conditional: true


condtition:


function checkWeekdays() {


var now = new Date();


var day = now.getDay();


var result = false;


if(day != 0 && day != 6) {


result = true;


}


return result;


}


checkWeekdays();


View solution in original post

12 REPLIES 12

Click on condition and use below script to check the day so that it will run on weekdays only.



var answer = false;


var now = new GlideDateTime();


if(now.getDayOfWeek() > 0 &&   now.getDayOfWeek() < 6){


    answer = true;


}


Run:onDemand


conditional: true


condtition:


function checkWeekdays() {


var now = new Date();


var day = now.getDay();


var result = false;


if(day != 0 && day != 6) {


result = true;


}


return result;


}


checkWeekdays();


Could this be modified to occur every 90 days?

Mickey, if you want the scheduled job to run once in every 90 days, you don't need the above script.

 

In scheduled script execution:

Run: Periodically

Repeat Interval: 90 days.

 

find_real_file.png

Hi Pridhvi


Select the run as weekly and then you will get the option on which weekday you want to run.No extra script required.




Regards


Harsh