
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2021 12:01 PM
hi all,
we have a service catalog wherein we let users request for database access.
Database | Group |
DB1 | Group 1 |
DB2 | Group 1 |
DB3 | Group 2 |
DB4 | Group 2 |
for the above example, if the access is requested for DB1, we take approval from group 1.
the ask is that we need to create 2 RITMs from the catalog for the above use case based on the approval group
Database | Group | RITM |
DB1 | Group 1 | RITM111 |
DB2 | Group 1 | RITM111 |
DB3 | Group 2 | RITM222 |
DB4 | Group 2 | RITM222 |
what is the best way to meet the use case? i can think of creating a custom interface using a ui page or a service portal widget for the same which would programmatically create multiple RITMs upon submission. is there a better and simpler approach to get the same result?
Thanks,
Ravish
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2021 12:26 PM
Hi Ravish,
We have done this with a CI list box - one RITM is created under the same REQ for each CI selected. This could also work if you have checkboxes or whatever. In the workflow for the catalog item we have this Run Script which 'resets' the current RITM to be for only the first CI selected, then creates an RITM for all of the other CIs, populates the same variables, and kicks off this same workflow. It seems to work pretty well - one Catalog Item with one workflow, and multiple RITMs under the same REQ.
var cilist=[];
var ritmsysid = '';
//get sysids of variables that will be populated on new RITMs
var v_db_cat = '9f29df1bdbe48f004a29df6b5e9619c3';
var v_integration_status = 'bbfcbc9cdb298b00262950a45e961958';
//get multiple values, split into an array
var items = current.variables.v_db_cat.toString();
items = items.split(',');
//if only one item was selected, set the values per usual
if(items.length == 1){
current.u_on_behalf_of = current.variables.v_requested_for;
current.cmdb_ci = items[0];
}
//or else set the values on the initial, existing RITM, and change the selected item to the first one
else{
current.u_on_behalf_of = current.variables.v_requested_for;
current.variables.v_db_cat = items[0];
current.cmdb_ci = items[0];
//create a new RITM under the same REQ for all of the other selected values
for (var i = 1; i < items.length; i++) {
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = current.request;
ritm.cat_item = current.cat_item;
ritm.opened_by = current.opened_by;
ritm.u_on_behalf_of = current.variables.v_requested_for;
var sysID = ritm.insert();
//Add variables to the new RITMs
addVariable(sysID, v_integration_status, current.variables.v_integration_status,1);
addVariable(sysID, v_db_cat, items[i],2);
}
//Start the workflow on all the new RITMs
startWf(current.request);
}
function addVariable(ritm,varID,value,order) {
var variable = new GlideRecord('sc_item_option');
variable.initialize();
variable.item_option_new = varID;
variable.value = value;
variable.order = order;
var sysID = variable.insert();
var itemm2m = new GlideRecord('sc_item_option_mtom');
itemm2m.initialize();
itemm2m.request_item = ritm;
itemm2m.sc_item_option = sysID;
itemm2m.insert();
}
function startWf(request) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request',request);
ritm.addQuery('sys_id','!=',current.sys_id);
ritm.addNullQuery('context');
ritm.query();
while (ritm.next()) {
ritm.setForceUpdate(true);
ritm.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2021 12:26 PM
Hi Ravish,
We have done this with a CI list box - one RITM is created under the same REQ for each CI selected. This could also work if you have checkboxes or whatever. In the workflow for the catalog item we have this Run Script which 'resets' the current RITM to be for only the first CI selected, then creates an RITM for all of the other CIs, populates the same variables, and kicks off this same workflow. It seems to work pretty well - one Catalog Item with one workflow, and multiple RITMs under the same REQ.
var cilist=[];
var ritmsysid = '';
//get sysids of variables that will be populated on new RITMs
var v_db_cat = '9f29df1bdbe48f004a29df6b5e9619c3';
var v_integration_status = 'bbfcbc9cdb298b00262950a45e961958';
//get multiple values, split into an array
var items = current.variables.v_db_cat.toString();
items = items.split(',');
//if only one item was selected, set the values per usual
if(items.length == 1){
current.u_on_behalf_of = current.variables.v_requested_for;
current.cmdb_ci = items[0];
}
//or else set the values on the initial, existing RITM, and change the selected item to the first one
else{
current.u_on_behalf_of = current.variables.v_requested_for;
current.variables.v_db_cat = items[0];
current.cmdb_ci = items[0];
//create a new RITM under the same REQ for all of the other selected values
for (var i = 1; i < items.length; i++) {
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = current.request;
ritm.cat_item = current.cat_item;
ritm.opened_by = current.opened_by;
ritm.u_on_behalf_of = current.variables.v_requested_for;
var sysID = ritm.insert();
//Add variables to the new RITMs
addVariable(sysID, v_integration_status, current.variables.v_integration_status,1);
addVariable(sysID, v_db_cat, items[i],2);
}
//Start the workflow on all the new RITMs
startWf(current.request);
}
function addVariable(ritm,varID,value,order) {
var variable = new GlideRecord('sc_item_option');
variable.initialize();
variable.item_option_new = varID;
variable.value = value;
variable.order = order;
var sysID = variable.insert();
var itemm2m = new GlideRecord('sc_item_option_mtom');
itemm2m.initialize();
itemm2m.request_item = ritm;
itemm2m.sc_item_option = sysID;
itemm2m.insert();
}
function startWf(request) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request',request);
ritm.addQuery('sys_id','!=',current.sys_id);
ritm.addNullQuery('context');
ritm.query();
while (ritm.next()) {
ritm.setForceUpdate(true);
ritm.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2021 08:09 AM
thanks, Brad. just what we were looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2021 10:43 AM
You are welcome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 06:24 AM
How would you avoid running RUN SCRIPT section for the workflows that got triggered for rest of the RITMs which we have generated from current workflow only?