Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to create Schedule job to trigger one catalog item to produce multiple RITMS to multiple users at a time

ramu15
Kilo Contributor

Hi All,

Need to create Schedule job to trigger one catalog item to produce multiple RITMS to multiple users at a time ,can you tell what script we need to achieve this?

Catalog item variable is "user" i.e  single variable only.

Please help to do this task.

Thanks in Advance,

2 REPLIES 2

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

You can use this with this script:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 //add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('4054428fdb151f0097679ec6db9619c0', 1);//4054428fdb151f0097679ec6db9619c0 is catalog item sys_id

//fill in the variables on the request item form
cart.setVariable(item,"u_requested_for", "user_sys_id"); //user_sys_id is a user sysid

var rc = cart.placeOrder();

 

You need to make the user sys id dynamic and put this above code in for loop for all that user.

var gr = new GlideRecord('sys_user');
gr.addQuery('active',true);
gr.setLimit(5);
gr.qeury();
while(gr.next()){
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 //add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('4054428fdb151f0097679ec6db9619c0', 1);//4054428fdb151f0097679ec6db9619c0 is catalog item sys_id

//fill in the variables on the request item form
cart.setVariable(item,"u_requested_for", gr.getValue('sys_id')); //user_sys_id is a user sysid

var rc = cart.placeOrder();
}


Thanks,
Ashutosh

Nitesh Alashe1
Giga Expert

Hello Ramu,

 

you can use the below script with static sys_id of catalog item to create RITM

var cart = new Cart();
// add the item and variables from the incident
var item = cart.addItem(sc_sysid);
cart.setVariable(item,'caller',current.caller_id);
cart.setVariable(item,'short_description',current.short_description);
cart.setVariable(item,'description',current.description);
// place the order
var rc = cart.placeOrder();
rc.requested_for=current.caller_id;
rc.short_description=current.short_description;
rc.description=current.description;
rc.update();

 

If my answer helped you in any way, mark answer as helpful and correct.

 

BR

Nitesh