- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-22-2022 12:22 AM
Hi All,
I have a workflow that creates a single task and other tasks team creates for approvals and stuff. The issue is, once the
workflow created task gets Closed the WF moves to end activity and stage is completed even when other manual tasks are still open. I tried writing a Before/update After/update BR but is not helping. Can you please help?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-22-2022 03:41 AM
Create a Wait for condition with following script:
var task = new GlideRecord("sc_task");
task.addEncodedQuery("stateNOT IN3,4^request_item=" + current.sys_id);
task.query();
var count = task.getRowCount();
if (count == 0)
answer = true;
You can put this inside a function as well. No need of any BR or additional field on RITM level.
Regards,
Rana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-22-2022 12:29 AM
Hello @sbeginner ,
Please create a custom checkbox field on RITM table. Use the same business rule to mark the checkbox as true when all the tasks are completed. Also add a 'wait for condition' activity in the workflow so that whenever the checkbox is checked then only move towards closure of the RITM.
The above configuration can achieve your requirement with minimum efforts.
Please mark my answer as correct if it helps.
BR,
Nayan
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-22-2022 12:37 AM
Hi Nayan, Thanks for your reply. Will try this in next 15 mins and reply back.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-22-2022 01:13 AM
Hi @Nayan Dhamane ,
I tested this as you said and it is now not moving to Closure after first task but it is not moving ahead even when all tasks are closed. Can you please have a look at BR and point out what is wrong please. It is a Before/Update BR on sc_req_item table. Also added wait for condition in WF, screenshot belwo:
(function executeRule(current, previous /*null when async*/) {
var taskCatItem = new GlideRecord('sc_task');
taskCatItem.addActiveQuery();
taskCatItem.addQuery('request_item', current.getUniqueValue());
taskCatItem.query();
if (taskCatItem.hasNext()) {
//there are still open tasks belonging to requested item, abort update
gs.log('Task is Open', 'SAP');
gs.u_all_tasks_closed = 'false';
gs.addInfoMessage('There is still at least 1 active child task for ' + current.getDisplayValue());
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-22-2022 01:51 AM
Hello @sbeginner ,
Please write a new business rule on after ,update on sc_task table and please use the below code in it:
(function executeRule(current, previous /*null when async*/) {
var ritm= new GlideRecord('sc_req_item');
ritm.addQuery('sys_id',current.request_item);
ritm.query();
if (ritm.next()){
var taskCatItem = new GlideRecord('sc_task');
taskCatItem.addActiveQuery();
taskCatItem.addQuery('request_item', ritm);
taskCatItem.query();
if (taskCatItem.hasNext()) {
ritm.u_all_tasks_closed='false';
ritm.update();
}
else {
ritm.u_all_tasks_closed ='true';
ritm.update();
}
}})(current, previous);
Please mark correct if it helps.
BR,
Nayan
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.