Adding ad hoc tasks which will
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 09:09 AM
Looking for some guidance. We have a few request workflows in our company that our Service Desk regularly have to raise "ad hoc tasks" during the lifecycle of the fulfilment should they require other teams to be involved.
Issue:
When the last WF task completes, the WF closes the RITM. That's all good. But now we are going to let users create ad-hoc tasks manually on the RITM. That means when the last WF task closes it will close the RITM and orphan the manually added tasks.
Looking for a business rule that if an ad hoc task is added that it will wait for all tasks to be close completed, closed incomplete, closed skipped and then the RITM will change the stage to Completed and state to Close Completed. See attached code I found and doesn't seem to work. Any help is much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 09:24 AM
Hi @Julie Catano ,
The below code will work
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
//Query for all tasks to see if they are inactive
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.request_item.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 12:19 PM
I updated the Business Rule with the above code and if the last task is an ad hoc task and I close it, the task closes but the RITM is still open and active, so it's still an orphan RITM. (see screen shot below)
The BR is running on all catalog items in our service catalog.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 12:35 PM
Hi @Julie Catano ,
Write the business rule like below
With conditions like below
and code as below
(function executeRule(current, previous /*null when async*/) {
//Query for all tasks to see if they are inactive
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
gs.addInfoMessage("Please close all the tasks before closing the request");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 12:58 PM
Make the order of business rule - 10200 to make sure that it executes after workflow