Create multiple RITMs based on list collector variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 07:02 AM
Hi Team,
I have a requirement for create multiple RITMS using List Collector variable, the variables should copy with in the RITM.
Help me on the same.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 07:08 AM
Hi Anil,
Your requirement is not clear.
Do you want to create multiple RITMs based on number of values in list collector?
One possible solution is as below :
> In your workflow, add a run script activity and use cart api to create ritms.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 09:09 AM
Hi Sumanth,
thanks for the reply
my code is
var opt = current.variables.select_user.toString().split(',');
for (i=0; i < opt.length; i++) {
createRequest();
}
function createRequest() {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('060f3afa3731300054b6a3549dbe5d3e', 1);
cart.setVariable(item, 'employee_type', current.variables.employee_type);
cart.setVariable(item, 'slt_number', current.variables.slt_number);
cart.setVariable(item, 'sales_force', current.variables.sales_force);
cart.setVariable(item, 'requestor', current.variables.requestor);
cart.setVariable(item, 'email', current.variables.email);
cart.setVariable(item, 'location', current.variables.location);
cart.setVariable(item, 'select_computer', current.variables.select_computer);
var rc = cart.placeOrder();
this is working but I want to set every RITM requested_for to list collector variable selected user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 09:14 AM
hello Anil i that case you need to do like this
var opt = current.variables.select_user.toString().split(',');
for (i=0; i < opt.length; i++) {
createRequest(opt[i].toString());
}
function createRequest(requestedFor) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('060f3afa3731300054b6a3549dbe5d3e', 1);
cart.setVariable(item, 'employee_type', current.variables.employee_type);
cart.setVariable(item, 'slt_number', current.variables.slt_number);
cart.setVariable(item, 'sales_force', current.variables.sales_force);
cart.setVariable(item, 'requestor', current.variables.requestor);
cart.setVariable(item, 'email', current.variables.email);
cart.setVariable(item, 'location', current.variables.location);
cart.setVariable(item, 'select_computer', current.variables.select_computer);
var rc = cart.placeOrder();
var gr =new GlideRecord('sc_req_item');
gr.addQuery('request',rc);
gr.query();
if(gr.next())
{
gr.request.requested_for= requestedFor.toString();
gr.update();
}
}
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 10:02 PM
Hey Anil,
You are almost done.
Only additional thing you need to add to your code is to pass each value of list collector as a parameter to your function which creates the request.
So that you can use it to update the RITM requested for field after generating RITM.
So your final code should look as below
var opt = current.variables.select_user.toString().split(',');
for (i = 0; i < opt.length; i++) {
createRequest(opt[i].toString());
}
function createRequest(requestedFor) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('060f3afa3731300054b6a3549dbe5d3e', 1);
cart.setVariable(item, 'employee_type', current.variables.employee_type);
cart.setVariable(item, 'slt_number', current.variables.slt_number);
cart.setVariable(item, 'sales_force', current.variables.sales_force);
cart.setVariable(item, 'requestor', current.variables.requestor);
cart.setVariable(item, 'email', current.variables.email);
cart.setVariable(item, 'location', current.variables.location);
cart.setVariable(item, 'select_computer', current.variables.select_computer);
var req = cart.placeOrder();
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', req);
gr.query();
if (gr.next()) {
gr.request.requested_for = requestedFor;
gr.update();
}
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth