- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 07:38 AM
I'm just thinking this through... feedback welcomed.
We have RITM with catalog tasks that are generated from workflow, which is good.
When the last catalog task is completed the RITM auto closes and if you try to close the RITM with a task still open it throws error and aborts. That is all good.
We are now going to let users just "Add" new catalog tasks to any RITM outside of the workflow. So, that means when the last catalog task from WF completes it will try to close the RITM but fail because there is an ad-hoc task still active. That is good too as long as the WF completes and the RITM remains open.
We can't change all the WF now to run a script at the end to check for any manually open tasks before the WF will close, so I need to create a business rule that fires on all catalog tasks that go to close.
My BR, I think, needs to do 2 things:
The parent RITM must not have any active tasks
AND
most important the parent RITM workflow must no longer be executing, right, because if I ad hoc a task then close it, I cannot close the RITM if it has more WF to go which will be creating more tasks. So my BR also has to look in wf_contect for the sysid of the RITM and check to make sure the state is not executing. How does this sound?
I did some brainstorming with other developers on how best to handle this scenario.
They all agreed that ad hoc tasks on a catalog item is unusual because catalog items are generally repeatable proven processes with a set of known tasks that are needed in order to fulfill a request. The WF can be the control as to when the RITM is closed when all necessary tasks are closed.
So what I might do to keep this transparent. I'll add a new custom field to the RITM that will show if the WF is still executing. Because if the WF is still executing, the ad-hoc tasks should not be allowed to close the RITM. It has to respect the parent WF. Then I may flag catalog tasks that are ad-hoc so we only need the BR to fire when an ad-hoc task closes. The BR that fires when an ad-hoc task completes will close the RITM if the RITM workflow is not executing and there are no other ad-hoc tasks active with the same parent RITM number.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 10:17 AM
Hello,
Yes you are correct you will need to query the wf_context table to see if there are any active flows for the RITM. Something like the below will work:
var gr = new GlideRecord('wf_context');
gr.addQuery('table', 'sc_req_item');
gr.addQuery('state', 'executing');
gr.addQuery('id', RITM SYS ID);
gr.addNullQuery('parent');
gr.query();
if(gr.hasNext()){
return; //Current Running WF so we stop script
} else{
var r = new GlideRecord('sc_task');
r.addQuery('request_item',RITM SYS ID);
r.addQuery('state','!=','complete');
r.query()
if(r.hasNext()){
return; //Open Catalog Task so we stop WF
}else{
CLOSE RITM
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2020 11:11 AM
Wouldnt this simply be resolved by having a 'Set Values' activity.
- Name: Close Request
- Stage: Completed
- Value: State is Closed Complete
Having that Completed Stage will close the REQ, which should in turn close the RITM. You can even through a pre-activity in that validates that all tasks are closed before moving to this activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2020 04:02 PM
Hi