Is it possible to create multiple RITM from a list collector?

JLeong
Mega Sage

Hi All,

'Hope everyone is safe and healthy.

Is it possible to create multiple requested items (sc_req_item) based on a list collector? For example, if I have 5 items listed from the list collector, it will also create 6 RITM. Like order guide but from a regular request form.

If so, please provide the steps to do it.

Thank you in advance.

Regards,

Jocelyn

 

1 ACCEPTED SOLUTION

Hi Saurab,

Thanks for sharing your script. It gave me ideas and helped me with what I need to accomplish.

I was able to create a catalog item for each list collector from a record producer. Attached is the script.

I also used Flow Designer to automate the fulfillment.

 

//*** cancel creation of global record ***//
current.setAbortAction(true);

//*** Create Service Catalog Request (SR) ***//
var newReq = new GlideRecord('sc_request');
newReq.initialize();
newReq.opened_by = gs.getUserID();
newReq.due_date = gs.endOfThisWeek();
newReq.short_description = 'ServiceNow Group Access Request';
if (producer.sna_request_for_other == 'no') {
newReq.requested_for = gs.getUserID();
} else {
newReq.requested_for = producer.sna_request_is_for;
}
var newID = newReq.insert();


//*** Create Catalog Item Request for added groups***//
var addGrp = producer.sna_groups_to_add.toString().split(',');
var remGrp = producer.sna_groups_to_remove.toString().split(',');

if (addGrp != '')
createItem(addGrp, 'Add User to Group');

if (remGrp != '')
createItem(remGrp, 'Remove User from Group');

function createItem(grpArray, addRemove) {
for (var i = 0; i < grpArray.length; i++) {
var userGrp = new GlideRecord('sys_user_group');
userGrp.addQuery('sys_id', grpArray[i]);
userGrp.query();
if (userGrp.next()) {
gs.log('Return Group= ' + userGrp.name); // Get group name
}

var newSI = new GlideRecord('sc_req_item');
newSI.initialize();
newSI.request = newID;
newSI.cat_item = 'a639c9db1bf7cc107b86542f0a4bcb0d'; // ServiceNow Group Access Catalog item
newSI.short_description = addRemove + ' - ' + userGrp.name;
newSI.due_date = gs.endOfThisWeek();
var newSIid = newSI.insert();

//*** Get the variables to be filled out in the User Options of the SI ***//
var itemName = newSI.cat_item.name;
var itemVar = new GlideRecord('item_option_new');
itemVar.addQuery('cat_item.name', itemName);
itemVar.query();
var itemVarList = [];
while (itemVar.next()) {
itemVarList.push(itemVar.getUniqueValue('name'));
}

//*** Populate Options - sc_item_option ***//
for (var x = 0; x < itemVarList.length; x++) {
var itemOption = new GlideRecord('sc_item_option');
itemOption.initialize();
itemOption.order = x;
itemOption.item_option_new = itemVarList[x];

if (itemOption.item_option_new == 'f2390d9f1bf7cc107b86542f0a4bcb6a') { // User requesting:
itemOption.value = newReq.requested_for;
}

if ((addRemove == 'Add User to Group') && (itemOption.item_option_new == '72390d9f1bf7cc107b86542f0a4bcb75')) { // Group to add
itemOption.value = userGrp.sys_id;
}

if ((addRemove == 'Remove User from Group') && (itemOption.item_option_new == '7e390d9f1bf7cc107b86542f0a4bcb6f')) { // Group to remove
itemOption.value = userGrp.sys_id;
}

var optionSysID = itemOption.insert();

//*** Populate Variable Ownerships - sc_item_option_mtom ***//
var itemM2M = new GlideRecord('sc_item_option_mtom');
itemM2M.initialize();
itemM2M.request_item = newSIid; // Parent Item
itemM2M.sc_item_option = optionSysID; // Dependent Value
itemM2M.insert();
}
}
}
gs.addInfoMessage("Thank you! Your request has been submitted - " + newReq.number);
producer.redirect = "sc_request_list.do";

View solution in original post

11 REPLIES 11

tsylte
Tera Contributor

Just wanted to say that I used this script in a Quebec environment and it worked great! Lots of possibility here for use cases where there's a gap in what Flow Designer can accomplish for you. Thanks for sharing!

Fred Jean
Tera Expert

You could also use the Cart API for this  :

https://docs.servicenow.com/bundle/tokyo-application-development/page/app-store/dev_portal/API_reference/CartJSScoped/concept/c_CartJSScoped.html