
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 06:17 AM
Within a parent request and based on an if condition, i would like to create a second RITM using the Cart API script.
I am able to create a separate request using the cart API however would like to create a second RITM instead to ensure both requests are linked together.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 12:26 PM
Thanks, to @randrews solution on Linked Post.
I was able to use the following code to create a second RITM on the current REQ. I'm still struggling with bypassing a switch statement on the 2nd RITM but i'm much closer.
//create a new item in the request
var CN = 'a391b983db497200e5f83220ad961958'; //sid for New Computer Catalog item
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, CN, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);
//find the item and update its variables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.addQuery('cat_item', CN);
grReqItem.addQuery('parent','');
grReqItem.query();
if(grReqItem.next()) {
grReqItem.variables.requester = current.variables.requester;
grReqItem.variables.requested_for = current.variables.requested_for;
grReqItem.variables.location = current.variables.requested_for.location;
grReqItem.variables.type_of_workstation = workflow.scratchpad.computertype;
gs.log("request item "+ grReqItem.variables.type_of_workstation);
grReqItem.variables.role = workflow.scratchpad.role;
grReqItem.variables.branch_suite_device = 'No';
grReqItem.variables.comments_box = workflow.scratchpad.comments;
grReqItem.parent = current.sys_id;
grReqItem.update();
}
If you have a switch statement at the beginning of the second workflow then you must add a 5 second timer to allow the switch statement to receive the value from the parent request.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 12:26 PM
Thanks, to @randrews solution on Linked Post.
I was able to use the following code to create a second RITM on the current REQ. I'm still struggling with bypassing a switch statement on the 2nd RITM but i'm much closer.
//create a new item in the request
var CN = 'a391b983db497200e5f83220ad961958'; //sid for New Computer Catalog item
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, CN, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);
//find the item and update its variables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.addQuery('cat_item', CN);
grReqItem.addQuery('parent','');
grReqItem.query();
if(grReqItem.next()) {
grReqItem.variables.requester = current.variables.requester;
grReqItem.variables.requested_for = current.variables.requested_for;
grReqItem.variables.location = current.variables.requested_for.location;
grReqItem.variables.type_of_workstation = workflow.scratchpad.computertype;
gs.log("request item "+ grReqItem.variables.type_of_workstation);
grReqItem.variables.role = workflow.scratchpad.role;
grReqItem.variables.branch_suite_device = 'No';
grReqItem.variables.comments_box = workflow.scratchpad.comments;
grReqItem.parent = current.sys_id;
grReqItem.update();
}
If you have a switch statement at the beginning of the second workflow then you must add a 5 second timer to allow the switch statement to receive the value from the parent request.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2022 04:34 AM
If you're looking for a way to achieve adding a new catalog item to an existing request with the CartJS API have a look at this Article:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 11:49 AM
Hi Kristy, I noticed there is a second and third RITM created after following your steps. How do I remove the second RITM that only have variables form the Original request copied over?
A Snippet attached.
RITM ending in 7180 is the original requested item
The one ending 7181 has the values in the original copied over with no flow context associated with it
The one ending 7182 is theactual 2nd RITM with all the details and flow associated.
Kindly provide your input.