
- 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:25 PM
Hello,
Do you mean you have a Workflow (on the sc_req_item table) and in that Workflow you have an IF condition and for one the branches (either True or False) you want to create a new RITM?
Also are the informations you want to set in the new RITM (on the form and variables) are coming from the inital RITM?
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 12:30 PM
That is correct. The variables could either come from form variables on the parent RITM or set variables that will be pushed to the 2nd RITM.
I have this accomplished mostly based on another post i found however my 2nd RITM has a switch statement where the activity.results == 'desktop'. The RITM is hanging on this switch statement regardless of how i pass the variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 12:44 PM
Are you able to test the workflow of your 2nd RITM separately of being created from the 1st one?
Somewhere in the Service Catalog add your catalog item associated to you 2nd workflow, fill in your variables and see if the workflow works and pass the switch statement.
This way it would give you a good idea if the problem is when you create the 2nd RITM or its workflow.
I would also suggest to maybe start the workflow of your 2nd RITM with a timer of 1-2 seconds. Maybe the workflow is triggered and gets to the switch statement just before all the variables are copied.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 12:56 PM
Thank you for your time on this. Adding the timer to the 2nd workflow allowed time for the switch statement to receive the value from the parent.