I written following code in "wait for condition" in work flow to stop workflow until to close all task records for particular request item, But this not working .

srikanth241
Mega Expert

Hi Team,

I written following code in "wait for condition" in work flow to pause the workflow until to close all task records for particular request item, But this not working, even all the tasks are closed but still it is in wait for condition only. It is not moving to further activities.

All these tasks are created dynamically trough run script from inputs of list collector.

Any Idea or inputs can help me a lot

code:

var gRT = new GlideRecord('sc_task');

gRT.addQuery('request_item',current.sys_id);

gRT.addQuery('active',true);

gRT.query();

  if(gRT.hasNext()){

  answer = false;

  gs.log('if'+gRT.hasNext());

  }

  else{

  answer = true;

  gs.log('else'+gRT.hasNext());

  }

Thanks.

Developer CommunityDiscussExperts CornerCommunity CornerConnect

1 ACCEPTED SOLUTION

That's a good point. Workflows only re-check when the record used against the workflow (e.g. RITM, change request) is updated. Updating child records isn't going to trigger the workflow on the parent record. To do this, you could force an update on the request_item when an update to the sc_tasl table is made.



An AFTER BR on the sc_task table something like this



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



var parent = new GlideRecord('sc_req_item');


parent.get(current.request);


parent.setForceUpdate(true);


parent.update();



})(current, previous);


View solution in original post

24 REPLIES 24

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Abhay,



Your wait for condition activity will wait till answer is false. once answer become true it will proceed further


here is the code



var query = 'request_item=' + current.sys_id + '^state!=3';


var taskRecord = new GlideRecord('sc_task');


taskRecord.addEncodedQuery(query);


taskRecord.query();


if(taskRecord.next()){


  answer = false;


}


else{


  answer = true;


}



you can add one more condition i.e. active=true based on your requirement


what this script does is it checks is there any task for this ritm which is not in closed complete is yes then wait. If it doesn't find any then answer=true it means all are tasks are closed for this ritm and it proceeds further.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi Ankur,




Thanks for your quick response .



This script is checking for open records for a particular request item , if it does not find any which means there is no open tasks for particular request item, it goes further and sets request item to closed state.



In my case even if I close all the tasks also , workflow still remains in wait for condition only it is not moving to further stage.



trough my debug i found that even after closing task , workflow is not triggering to check for wait condition.



any help..?


Thanks.


anurag92
Kilo Sage

Is the workflow progressing after nudging?


Nope Anurag,workflow is not moving further. even after closing tasks it is in wait for condition activity only it is not progressing to further state.


any idea..?


Thanks,


Nithin.