workflow hanging on wait for condition....sometimes

Community Alums
Not applicable

I've got a workflow that seems temperamental. Everything is working fine until I get to a "Wait for Condition" where it sometimes works and other times just sits there.

The Wait for Condition is waiting for the task that is generated by the workflow to be assigned, and then it is supposed to allow the workflow to advance. I have a script in the workflow that is checking for the task to be assigned, not sure if this is what's causing it or something else.

var gr = new GlideRecord('sc_task');
gr.addQuery('parent', current.sys_id);
//gr.addQuery('assigned_to', '!=', '');
gr.query();

if (gr.next()){
if (gr.assigned_to != ""){
  answer = true;
}
else{
  answer = false;
}
}
else{
answer = false;
}

Here is my workflow just for reference:

find_real_file.png

1 ACCEPTED SOLUTION

So, I went and pulled up the BR that's referenced in that runFlows documentation. Looks like there's a new function that handles this now. Here's the script from that BR.



var gr = new GlideRecord(current.parent.getTableName());


gr.addQuery("sys_id",current.parent.toString());


gr.query();


if (gr.next()) {


          new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);


}



I think you'll want to use the script in line 5 in your BR instead.


View solution in original post

9 REPLIES 9

Community Alums
Not applicable

I tossed logs in the BR and its running, the wkfw.runflows(current.request_item, 'update'); is returning the sys_id of the record, that's correct.



I know the wait for condition is working correctly as if I add something to description and save it, it fires the wait for and moves the flow along. I just need to get it to update/run the workflow again.


One other thing. I believe that function is actually looking for a GlideRecord for the first argument. What you're providing is likely just the sys_id of the record. You may want to instantiate a GlideRecord and get the RITM and pass that in.


So, I went and pulled up the BR that's referenced in that runFlows documentation. Looks like there's a new function that handles this now. Here's the script from that BR.



var gr = new GlideRecord(current.parent.getTableName());


gr.addQuery("sys_id",current.parent.toString());


gr.query();


if (gr.next()) {


          new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);


}



I think you'll want to use the script in line 5 in your BR instead.


Community Alums
Not applicable

Ok got it working -



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


// Add your code here


var gr = new GlideRecord("sc_req_item");  


gr.addQuery("sys_id",current.request_item.sys_id);  


gr.query();  


if (gr.next()) {  


          new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);


}


})(current, previous);



Thanks a ton for the Help I really appreciate it!


sasi_v
Tera Guru
HI
KVanWagner/awessel
 
I have a similar requirement ,but the issue is I'm using  two Wait for Condition under one task.By using above BRule Only first condition is getting triggered but second condition is hanging.
 
Kindly help me