- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2017 08:09 AM
Currently using ISTANBUL
Objective: Create a second RITM under new REQ using script in Workflow. This RITM would then trigger it's corresponding workflow.
Details:
We have a Catalog Item (New Provider) that allows our organization to ask for a onboarding staff to have specific permissions in a medical setting. Training is also required for this new individual. There is a separate Catalog Item used by our training team that allows them to track completion and communicate requirements for New Providers and other similar REQs (generally submitted via email).
Our goal is that when a new Provider is ordered from the Service Catalog, it's corresponding workflow will contain an activity that will generate a second RITM for the Training team under the same REQ.
I tried adding the following script to the New Provider Catalog Item in the "Delivery Plan Script field. This didn't do anything at all which makes me wonder if I don't fully understand its purpose...or more likely, the script is faulty:
var reqItem = new GlideRecord('sc_req_item');
reqItem.initialize();
reqItem.request = current.request.sys_id;
reqItem.cat_item = '80df599bdba3320007a2fe1ebf9619ff'; //Sys_id of Training Catalog Item
reqItem.short_description = "Training Tracking for New provider";
reqItem.stage = "request_approved";
reqItem.approval = "requested";
reqItem.insert();
I added the same script to Run Script activity in the New Provider workflow. A second RITM was created under the same REQ...BUT (and it's a big one) the Training Workflow was not run or tied to the new REQ. I did search online and couple of posts directed me here, but that is what I tried first.
Any advice on what I am missing?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2017 02:59 PM
this is a script i use to create a number of new req items inside an existing request.. it is wrapped in a for loop since it is going to crerate multiple items.. just eliminate that loop... bottom line is FIRST you create the item... and associate to the current request.. THEN you go through and set all variables that you need.. so where i am setting the variables.. take mine out put in yours and add any lines needed to get em all..
my apologies to whoever i stole this code/idea from! this runs in a script box inside of your workflow.. obviously replace the sys_id i have in my code with your own<the sys id for the maintain item you are creating an item for>
list = current.variables.v_xxxx_additional_secured_area_acc.toString();
var list_split = list.split(',');
var secure_area = 'e891c69d13a1fe008e9c7e276144b03c'; //sid for the wecure item access
for(var counter = 0 ; counter< list_split.length; counter++){
//create a new item in the request
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, secure_area, 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);
//find the item and update itsvariables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.addQuery('cat_item',secure_area);
grReqItem.addQuery('parent','');
grReqItem.query();
if(grReqItem.next()) {
//gs.addInfoMessage('Found item ' + grReqItem.number);
grReqItem.variables.requested_for = current.variables.requested_for;
grReqItem.variables.v_area = list_split[counter];
grReqItem.parent = current.sys_id;
grReqItem.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2017 09:04 AM
have you checked what is the start condition in your second workflow? may by the RITM you had created through script that did not execute the start condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2017 11:55 AM
Thanks for replying. The Training-Tracking (2nd workflow) is on the Requested Item table. As such, I am unable to set conditions.
To test your theory, I did create a new Workflow on the Request table so I could set a proper condition. I wanted the Workflow to run when the short_description equaled a specific value. The testing showed that the workflow did trigger, but it did not appear to do anything. No errors. No new RITM. Nothing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2017 11:32 AM
Hi Kevin,
Can you please try testing this code.
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if(gr.next())
{
var reqItem = new GlideRecord('sc_req_item');
reqItem.initialize();
reqItem.cat_item = '80df599bdba3320007a2fe1ebf9619ff'; //Sys_id of Training Catalog Item
reqItem.short_description = "Training Tracking for New provider";
reqItem.stage = "request_approved";
reqItem.approval = "requested";
reqItem.insert();
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2017 11:56 AM
Thanks for the Reply. I tried this code and nothing happened.