Script to add multiple RITM to single request

maryc
Tera Contributor

Hi ,

 

Is there a script to add multiple RITMS to single request? My requirement is that the catalog item can have multiple users in a variable and for each user a separate RITM has to be created under a single REQ

2 REPLIES 2

Sai Kumar B
Mega Sage
Mega Sage

@maryc 

If you've got a workflow associated with your catalog item then add the following script in the Run script activity

var users = current.variables.variable_name;

for(var i = 0 ; i< users.length ; i ++){
	var createRitm  = new GlideRecord('sc_req_item');
	createRitm.initialize();
	createRitm.setValue('cat_item', current.getValue('cat_item'));
	createRitm.setValue('request', current.getValue('request'));
	createRitm.insert();
}

If I could help you with my response you can mark it as helpful and correct as it benefits future viewers
Thanks,
Sai Kumar B
Community Rising Star 2023 & 2022

Faizeal Mohamed
Tera Guru

Hi,

 

We should use cart API to achieve this.

 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var users = current.variables.variable_name;

for(var i = 0 ; i< users.length ; i ++){
    var item = cart.addItem('<< you're catalog item sys id>>', 1);

     //fill the right variable names as per your catalog item
    cart.setVariable(item, "requested_for", current.variables.requested_for);
    cart.setVariable(item, "variable_name", current.variables.variable_name);
}
var rc = cart.placeOrder();
gs.info(rc.number);
 
Please try this script and let me know.
 
Thanks,
Faizeal.