- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2018 08:02 AM
I have kind of a tricky situation which I am trying to figure out how to approach.
We have an Order Guide with three Catalog Items to choose from. The Order Guide itself does not have a workflow attached to it. 2 of the 3 Catalog Items in my Order Guide do. They are pretty straight forward, creating a single RITM, so those Workflows run off of sc_req_item and are available to be selected from the Workflow field on the Catalog Item.
However, my third one is a bit trickier. It needs to create multiple RITMs, so the Workflow needs to run against sc_request so we can create multiple RITMs within that workflow. However, when we create a workflow based on sc_request, it is not available to be selected from the Workflow field on the Catalog Item.
I see from Workflow -> Properties -> Conditions, I could try to set a condition of which the workflow should run. We have done this before, based on the Order Guide value. However, that Order Guide was pretty straight forward and didn't have three different Catalog Items, each with their own workflow, listed underneath it. So the Order Guide field,in and of itself, does not contain enough information regarding when the workflow should be called. It is dependent upon the Catalog Item selected in the Order Guide (have a variable for that selection).
So, how can I do this? How can I set up the Workflow for this third option to run off of sc_request and get it to be called when that third option is selected?
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2018 12:47 PM
This is what I have used to trigger new items from an initial item and added to the same request.
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request,<sysID of the item>, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);
My use case:
We had an item that collected multiple share file locations, but needed individual approvals for each location. My setup was an initial item that runs a script with this code in it to generate the individual items under the same REQ. The original item closes automatically after the fact, so one 'item' spawns x number of individual items (dependent upon how many share file locations they request), all on the same REQ.
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=GlideappCalcHelperAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 06:30 AM
So this is how I inserted it into my Run Script action, and it created each RITM under its own separate REQ.
//capture key fields from original ritm
var orig_sys_id = current.sys_id;
var orig_req = current.request;
var orig_ritm = current.number;
var orig_submitter = current.opened_by;
var orig_bene = current.u_beneficiary;
var orig_short_des = current.short_description;
var orig_cat_item = current.cat_item;
var orig_due_date = current.due_date;
//capture key fields off of catalog item
//var role_owner = current.variables.facets_add_role_owner;
var applications = current.variables.facets_applications_role_needs_access_to; //list collector
//split applications list collector
var ind_app = applications.toString().split(',');
//loop through each application and create a new ritm
for(var i = 0; i < ind_app.length; i++){
var app = ind_app[i];
//get facets application name
var app_name= '';
var a = new GlideRecord('u_facets_application_owners');
a.addQuery('sys_id', app);
a.query();
while (a.next()) {
app_name = a.u_application;
}
var cart = new Cart(null, gs.getUserID()); //Create the cart as the current user
var item = cart.addItem('197ced5fdba5234080e972ec0f9619b7'); //id of catalog item
cart.setVariable(item, 'request', orig_req);
cart.setVariable(item, 'cat_item', orig_cat_item);
cart.setVariable(item, 'u_beneficiary', orig_bene);
cart.setVariable(item, 'due_date', orig_due_date);
cart.setVariable(item, 'opened_by', orig_submitter);
cart.setVariable(item, 'short_description', app_name);
cart.setVariable(item, 'u_sub_ritm', true);
var rc = cart.placeOrder();
}
//delete original ritm
var ritm2 = new GlideRecord('sc_req_item');
ritm2.addQuery('number', orig_ritm);
ritm2.query();
ritm2.next();
ritm2.deleteRecord();
Any ideas on what I am doing wrong?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 06:55 AM
Since your in a loop it is creating a new cart each time you loop thought. Maybe if you move this line var cart = new Cart(null, gs.getUserID()); above you for loop it will only create one cart and then you can add all the items to the same cart which should put it under the same request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 07:11 AM
I was hopeful, but it still put each RITM under its own REQ.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 07:16 AM
Oh forgot about var rc = cart.placeOrder(); probably needs to be called after the loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 07:51 AM
Well, that sort of worked. It did list all the newly created RITMs under a single REQ, but it is not the original REQ, but rather a new one.
The concern with that is that the user will be submitting it through the Service Portal, and when finished, will get a pop-up confirmation referencing something like REQxxxxxx1, but everything will be located under REQxxxxxx2. That will cause a bit of confusion. Is there any way to get the new RITMs created under the original REQ using this method?
The other issue I am having is getting all the original Variable fields from the Catalog Item displayed on the original RITM copied over to the new RITMs.