- 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-17-2023 07:34 AM
@FredrikT It is not good practice to listen for the state of change_request in a work flow which handles the RITM. Because RITM workflow will not listen for record changes of change_request table. It is better to handle them in business rule only.
Are you creating
If you want the logic for BR I can help you.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 07:42 AM
Great. yes, I could use help with the BR logic to set the RITM to closed complete when all related Changes Requests are closed for a particular item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 05:50 PM - edited 10-17-2023 05:51 PM
@FredrikT try this code in your After Update Business Rule on Change Request table.
(function executeRule(current, previous){
var gr = new GlideRecord("change_request");
gr.addQuery("parent", current.paren.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)){
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:06 AM
Thank you, that is very helpful but this condition is only for a particular RITM not any/all RITMs with related Change Requests so how would I call that out to only apply if cat_item or the RITM = [a specific item] ?