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

HarshTimes
Tera Guru

Hi Prudhvi


Write below script in the scheduled job and update that according to the comment.



var cartId = GlideGuid.generate(null);


var cart = new Cart(cartId);


var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f'); // Put the sys_id of the catalog item that you want to raise the request


cart.setVariable(item, 'os', 'Linux Red Hat'); // set the other variables of your catalog item accordingly


var rc = cart.placeOrder();


gs.info(rc.number);




See the below link for the details


http://wiki.servicenow.com/index.php?title=Service_Catalog_Script_API#gsc.tab=0




-Harsh


Thanks for the reply Harsh.



I just have one doubt with the line     -       cart.setVariable(item, 'os', 'Linux Red Hat'); // set the other variables of your catalog item accordingly



In this line, 'os' is the name of the variable in the catalog item and 'Linux Red Hat' is the value of it. Am I right? Please let me know.



Thanks.


Yes, you are correct.


Hi,



I have another issue here.I have to run this scheduled job only on weekdays. But, I don't find such an option in Scheduled Jobs.



Screenshot (691).png



What should I do now? Please let me know.