Add new RITM to existing REQ and update the new RITM Variables via a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 02:46 PM
I am trying to script a whay to add new RITMs to an existing request, but it does not seem to be working. I got it to add a new RITM to the request, but the new RITM has the default variable values in it, and not the new ones.
my 4 variable in the RITM are:
request_type
hostname
alias
network_tier
My code is:
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 02:53 PM
Can you try below in Background script and share the output with me?
var Req_SysID = 'b0f5bd85db83101080d984da0b961959'; //Hard code for testing
var CN = 'd04db306dba5501080d984da0b9619ca'; //sid for Catalog Item
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(Req_SysID, CN, 1); // 1 is the qty
reqHelper.rebalanceRequest(Req_SysID);
//find the item and update its variables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', Req_SysID);
grReqItem.addQuery('cat_item', CN);
grReqItem.addNullQuery('parent');
grReqItem.query();
gs.info('After ITEM Query - before variables'); // Comment to see where the script is executing
gs.info("COUNT OF RITM FOUND - " + grReqItem.getRowCount());
if(grReqItem.next()) {
gs.info("INSIDE IF");
grReqItem.variables.request_type = 'test';
grReqItem.variables.hostname = 'host name'
grReqItem.variables.alias = 'alias name';
grReqItem.variables.network_tier = '24';
grReqItem.parent = Req_SysID;
grReqItem.update();
gs.info('Variable IF Statement ran'); //Comment to see if the IF statement ran
}
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 07:46 AM
Thanks for helping. I ran this code, it created the RITM under the request and did not update the variables. The output was:
*** Script: After ITEM Query - before variables
*** Script: COUNT OF RITM FOUND - 174
*** Script: INSIDE IF
*** Script: Variable IF Statement ran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 10:30 AM
Update - the number of RITM's found was 174, but there are over 200 RITMs on this request. The point of this code was to be part of a larger set that parses an excel sheet and creates RITMs based on the rows in the sheet. I created a new request, and your code worked on the new request. It also worked on the parsed Excel sheet with only 4 rows.
After testing around, it appears this code is working on requests with a low number of RITMs. Is there a cap on the RITMs you can script to? I'll test around and see if there is a cap.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 10:44 AM
Thank you for the update, Daryn. There is no such limit. Can you re-check and apply the below queries in the RITM list and validate the number of counts. If our queries are correct then the list must give you 174 items just as script.
grReqItem.addQuery('request', Req_SysID);
grReqItem.addQuery('cat_item', CN);
grReqItem.addNullQuery('parent');
I doubt 26 missing RITMs may have parent field already filled in. Can you please validate once in the list and let me know.
If my responses helped you in any way, then helpful tag is appreciated.
-Sharjeel
Muhammad