- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 08:11 AM
Hi all,
We've got an issue raised by a customer where the requested item record is getting closed when manual tasks are closed even if there are other active tasks. They want the requested item to get closed only when all tasks are closed, but they also want the option to manually close the RITM even if it has active tasks (not best practice though).
A solution would be to check if there are remaining active tasks when a task is set to close complete and if there are, don't set the state of the requested item to closed complete. However, I'm not sure how to achieve this. I've compared the workflow with the one in my PDI and they are the same, and OOTB behaviour is that the RITM should close when all tasks are closed - this works fine on my instance but not on the customer's. Could someone please help me with this, all ideas are welcome!
Thanks
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 04:22 AM
They want to be able to close RITMs with open tasks (in this case, only the state changes to closed complete but the stage will be complete only when all tasks are closed - they shouldn't do this anyway but they are not following the right process). But they have this issue where whenever you close one manual task, the state/stage of the requested item moves straight to closed complete even with other tasks left.
I've actually tried something and it seems to be working. I've added a new activity called Wait for Condition that goes after Wait for Task to Complete. I've used this code in the script and it seems to be working:
var tskRec = new GlideRecord("sc_task");
tskRec.addQuery('request_item', current.sys_id);
tskRec.addQuery('active', "true");
tskRec.query();
if (tskRec.next()) {
answer = false;
} else {
answer = true;
}
Thank you for your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 09:05 AM
Could you please provide the code where this check is occurring in your customer's workflow?
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 06:49 AM
Hi Christopher,
The customer is using the Item Designer Fulfilment workflow and the config is per OOTB. I assume the check is occuring in the activity 'Check sequence fulfilment' and this is the only code in the script:
sc_ic_Factory.wrap(current,gs,workflow).checkSequenceFulfilment();
My PDI is using Service Request Item workflow and there is a step there called Catalog Task which waits for all tasks to complete. I've tried adding this one to the customer's workflow but it didn't work. Whenever a task is closed, the RITM gets closed too even if it has other active tasks linked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 10:43 AM
Got it - so the checkSequenceFulfilment() function is defined in the global.sc_ic_RequestedItem script include which is Read-only so you won't be able to modify the below code:
checkSequenceFulfilment: function() {
this._wf.scratchpad.fulfilment = {"success": true};
// If there are any tasks at this stage which are not in a close-incomplete state then continue as normal.
var rt = new GlideRecord(sc_.TASK);
rt.addQuery("request_item",this._gr.getUniqueValue());
rt.addQuery("state","!=",sc_ic.CLOSED_INCOMPLETE);
rt.addQuery("order",this._wf.scratchpad.taskSeq.data[this._wf.scratchpad.taskSeq.index]);
rt.query();
if (rt.getRowCount() == 0) {
this._log.debug("[checkStageFulfilment] Stage not completed, fulfilment cancelled.");
this._wf.scratchpad.fulfilment.success = false;
}
},
It gets a little bit tricky to leave the requested item open if there are still manually created tasks that are open -- you could modify the Item Designer - Fulfilment workflow to add a Workflow Activity between the If Stage fulfillment success and Return Value Return fulfilment status activities for Wait for WF Event, and then figure out how to trigger that WF Event only if there are no more active tasks belonging to the requested item:
But it's not going to be very straightforward to trigger the WF Event properly when there are no more active tasks since you will need to get the sys_id of the workflow context running against your requested item.
Probably the easier solution I'd recommend would be to create a new business rule on the sc_req_item table which is triggered Before Update where Active changes to false, and check if there are any open tasks belonging to the requested item. If there are, abort the update to close out requested item. You can also optionally specify if this business rule should only apply to requested item's where the catalog item's workflow is Item Designer Workflow:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var taskGr = new GlideRecord('sc_task');
taskGr.addActiveQuery();
taskGr.addQuery('request_item', current.getUniqueValue());
taskGr.query();
if (taskGr.hasNext()) {
//there are still open tasks belonging to requested item, abort update
gs.addInfoMessage('There is still at least 1 active child task for ' + current.getDisplayValue());
current.setAbortAction(true);
}
})(current, previous);
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 06:02 PM
Hi Christopher,
Thank you for the detailed response. I've initially created a similar BR as a solution but the customer was not satisfied as they would still like to be able to close RITM records even if there are open tasks. Looking at that function in the script include, I think there must be an issue somewhere because the remaining active tasks are not picked up and it might be worth raising a case with ServiceNow. I don't have a lot of workflow knowledge to be honest and adding that new step and looking for a way to trigger the WF is probably beyond me.