workflow is getting stuck here and not moving even after the task has cloed

lakng
Tera Contributor

here we have an issue in the workflow , as per the flow once the 1st task has closed / closed no response the next task has to be created. but after 1st task closed no response the workflow is still waiting for in the "wait for condition".

this wait for condition will check if any manually created tasks are still open or not. if all closed then it has to move further. 

here the closed no response state is -9

here the code used in the wait for condition.

answer=testCondtion();
function testCondtion(){

var prbTaskCloseComplete = new GlideRecord("problem_task");
prbTaskCloseComplete.addEncodedQuery('problem='+current.sys_id+'^stateIN3,4,7,8,-9^short_description=SDD to Provide CHI RCA Approval');
prbTaskCloseComplete.query();
gs.info('---Test Condtion----');
if(prbTaskCloseComplete.getRowCount() > 0){
return true;
}
else{
gs.info('---Test Condtion----'+'false');

gs.info(prbTaskCloseComplete.getRowCount());
return false;
}

}

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Workflow wait for condition will only work when

1) Update happens on same table on which workflow runs

In your case you are checking problem_task table and workflow is running on problem table

So you should mimic an update on problem via after update BR on problem_task

BR: Active [Changes To] False

Script:

(function executeRule(current, previous /*null when async*/) {

var wf = new Workflow();
var ri = new GlideRecord("problem");
if (ri.get(current.problem)) {
wf.runFlows(ri, 'update');

}
})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Hi,

in that BR itself you can add that code I shared.

Script I shared will mimic an update on problem so that workflow knows update happened and will evaluate the wait for condition and proceed if all tasks are closed.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

bhumika2
ServiceNow Employee
ServiceNow Employee

Use broadcastEventToCurrentsContexts instead of runFlows in above code