Multiple RITMs for the same request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2017 07:30 PM
Hi Community,
Is there any ways to have multiple multiple RITMs depending on Quantity selected? I need run each RITM workflow individually instead of one workflow for all requested items.
Seems like using Add cart capability, i can add same item multiple times and once cart is placed, it created multiple items and that what I wanted to do, but from the user perspective that could be cumbersome to click the "Add to Cart" button 10 times to add to cart (If user need 10 items)
Any help will be much appreciated,
Thanks
Ak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2017 11:31 PM
Hi
We are doing the same with consumable items in our catalog. We allow users to order 10 mice or keyboards, and then split them up into seperate RITM's.
The problem is that there are no documentent way of adding a new RITM to an existing request if the item has variables.
Luckily for us our consumables do not have any variables, so it is quite easy to do the split using a business rule
It runs async on insert:
split(current);
function split(current) {
//If more than one piece of a consumable model is ordered, generate multiple items for this model.
var qty = current.quantity;
for (var i=2; i<= qty; i++) {
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.state = current.state;
ritm.request = current.request;
ritm.cat_item = current.cat_item;
ritm.price = current.price;
ritm.short_description = current.short_description + " (" + i + " af " + qty + ")";
ritm.u_information_for_notification = "<div/>";
ritm.insert();
}
var me = new GlideRecord('sc_req_item');
me.get(current.sys_id);
me.short_description+= " (1 of " + qty + ")";
me.quantity = 1;
me.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 02:38 PM
Hi Lars,
Thanks for reply. In my case, I have lots of variables (around 40) that needs to copies over to the new RITM as I have a workflow that looks at the variable to initiate a REST call to vRA for orchestration.
Thanks
Ak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 11:42 PM
Hi
We have other catalog items where we split one item into many, which contain variables. It is something that I have "invented" myself and in no way
documented.
Here is an example of a script used in an item, where our servicedesk can order updates for multiple assets (they dont have direct access to our asset base).
For every asset selected in the list collector in the catalog item, an item is created in the created request, to process the change for the asset.
You should be able to use this to split yours.
generate();
function generate() {
//Sys IDs of Variables in the "Updating Asset and CI" catalog item
var isServerVar = '7bf2c1626f7ef500e75928112e3ee41f'; //Set to no
var assetVar = '1d91668f6fbf6900e75928112e3ee45f';
var statusVar = 'cf12aa0f6fbf6900e75928112e3ee432';
var server_statusVar = '87073b5f6ff64a00e75928112e3ee4cb'; //Set empty
var stockroomVar = "9ab1ba876fd68200e75928112e3ee445";
var keep_entitlementsVar = "49629b656f227500e75928112e3ee48f";
var userVar = "6ff21f656f227500e75928112e3ee4d5";
var timeVar = "626cc9016ff31200f62495cbbb3ee45c"; //Set empty
//Get selected assets
var asset = new GlideRecord('alm_asset');
asset.addQuery('sys_id','IN',current.variables.asset_collection);
asset.query();
while (asset.next()) {
//Create a new Request Item on the current request
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = current.request;
ritm.cat_item = 'd950228f6fbf6900e75928112e3ee49e'; //Updating Asset and CI
ritm.opened_by = current.opened_by;
var sysID = ritm.insert();
//Add variables to the Request Item
addVariable(sysID, isServerVar,'no',1);
addVariable(sysID, assetVar,asset.sys_id,2);
addVariable(sysID, statusVar,current.variables.new_status,3);
addVariable(sysID, server_statusVar,'',4);
addVariable(sysID, stockroomVar,current.variables.stockroom,5);
addVariable(sysID, keep_entitlementsVar,current.variables.keep_entitlements,6);
addVariable(sysID, userVar,current.variables.assign_to,7);
addVariable(sysID, timeVar,'',8);
}
//Start the workflow on all the created Items
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
‎03-27-2017 06:33 AM
Hi Lars,
Its a very helpful code.
There is another wiki entry, which might help in similar scenarios;
Order a Service Catalog Item from a Script - ServiceNow Wiki
Regards,
Shilpa