How do I schedule a requested item

TheSonOfMogh
Kilo Contributor

Hey Everyone!

 

Quick question for anyone who has experience with this.

 

I am trying to automate a checklist for our network security team.

I have built a catalog item, created an execution plan that contains all the tasks required, and all of that works perfectly fine and well.

 

However I seem to be having issues trying to "schedule" this item using the Scheduled jobs which seems to be driven off templates.

I tried to create a template with all the right values, the only issue is it creates an item (with no parent request) and my Execution plan does NOT get applied.

Any creative ideas or pointers in the right direction would be enormously helpful.

 

Thanks!!

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

I would have used a Workflow instead of the Execution Plan, but that is OK  



What you would need to do is use the Service Catalog Script API - Service Catalog Script API - ServiceNow Enterprise Wiki



Select the "System Definition \ Scheduled Jobs" Module and click on the New button in the list header.   Then click on the "Automatically run a script of your choosing" option:



Interceptor.png



Use the following example code:



(function(){


  var cart = new Cart();


  var item = cart.addItem("e2132865c0a8016500108d9cee411691");


  cart.setVariable(item, "replacement", "Yes");


  cart.setVariable(item, "original", "555-123-4567");


  cart.placeOrder();


})();



The sys_id you see on the 3rd line is for the example BlackBerry Z10 catalog item.   Replace it with the sys_id of your catalog item.   It sets two variables and then orders the item.



Your Scheduled Script Execution record should look similar to this:


Script.png


Set your scheduling info and you are set.   Click on "Execute Now" to try it out.   This will create the Request and Requested Item records for you.   If you need some special scheduling conditions on the Scheduled Job, check out this post - Custom Discovery Schedule with a Condition Script



You could even add the "Run as" field to the form and specify a particular user if you want to have that user as the "Requested for" on the Request.   You can see it in demo015 at the moment (for the next 23 hours or so).


View solution in original post

4 REPLIES 4

Jim Coyne
Kilo Patron

I would have used a Workflow instead of the Execution Plan, but that is OK  



What you would need to do is use the Service Catalog Script API - Service Catalog Script API - ServiceNow Enterprise Wiki



Select the "System Definition \ Scheduled Jobs" Module and click on the New button in the list header.   Then click on the "Automatically run a script of your choosing" option:



Interceptor.png



Use the following example code:



(function(){


  var cart = new Cart();


  var item = cart.addItem("e2132865c0a8016500108d9cee411691");


  cart.setVariable(item, "replacement", "Yes");


  cart.setVariable(item, "original", "555-123-4567");


  cart.placeOrder();


})();



The sys_id you see on the 3rd line is for the example BlackBerry Z10 catalog item.   Replace it with the sys_id of your catalog item.   It sets two variables and then orders the item.



Your Scheduled Script Execution record should look similar to this:


Script.png


Set your scheduling info and you are set.   Click on "Execute Now" to try it out.   This will create the Request and Requested Item records for you.   If you need some special scheduling conditions on the Scheduled Job, check out this post - Custom Discovery Schedule with a Condition Script



You could even add the "Run as" field to the form and specify a particular user if you want to have that user as the "Requested for" on the Request.   You can see it in demo015 at the moment (for the next 23 hours or so).


Did this help you out?   If so, can you mark the question as being answered so other Community members know that it is a good solution?   Thanks


Jim thank you so much for your suggestion, I gave this a try and it was perfect!



Cannot thank you enough for your quick and extremely well written response.   Have a wicked day!


You are welcome!