- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 07:02 AM
I have a Catalog Item using traditional workflow with multiple SCTASKs that eventually results in one or more related Change Requests being attached to the RITM. I am trying to have the RITM close ONLY when ALL related Change Requests have been closed. Currently using a Wait for condition in the workflow for "Wait for Change to Close" the RITM gets closed when the 1st related Change Requests is closed, not all of them. Is there a better way? Many suggest an after business rule however I have not found any examples that spell out what I need to do for my particular scenario.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 06:15 AM
@FredrikT You can use the following script to add that check. You need to replace YOUR_CATALOG_ITEM_SYS_ID in the script with your catalog item sys_id.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.parent.sys_id);
gr.addEncodedQuery("stateNOT IN3,4");
gr.query();
if (!gr.hasNext()) {
var ritmGr = new GlideRecord("sc_req_item");
if (ritmGr.get(current.parent.sys_id)) {
var cat_item_id = ritmGr.getValue('cat_item') + '';
if (cat_item_id == "YOUR_CATALOG_ITEM_SYS_ID") {
ritmGr.state = '3';
ritmGr.stage = 'closed_complete';
ritmGr.update();
}
}
}
})(current, previous);
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 06:15 AM
@FredrikT You can use the following script to add that check. You need to replace YOUR_CATALOG_ITEM_SYS_ID in the script with your catalog item sys_id.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.parent.sys_id);
gr.addEncodedQuery("stateNOT IN3,4");
gr.query();
if (!gr.hasNext()) {
var ritmGr = new GlideRecord("sc_req_item");
if (ritmGr.get(current.parent.sys_id)) {
var cat_item_id = ritmGr.getValue('cat_item') + '';
if (cat_item_id == "YOUR_CATALOG_ITEM_SYS_ID") {
ritmGr.state = '3';
ritmGr.stage = 'closed_complete';
ritmGr.update();
}
}
}
})(current, previous);
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 06:51 AM
Perfect! Thank you so much!