How to write condition for wait for all task to complete

keerthi19
Tera Guru

Hi ,

How can we write wait for condition in workflow. I have functionality called dynamic task creation.based on user input number of task will be creation.but until the all task closure ticket should not go to closed completed. Can anyone help this scenario.I tried many ways but no luck.

If all task closed sussfully it should go to closed completed status.otherwise if anyone of the tsk closed incomplete it should go to false condition.

3 REPLIES 3

Suresh1
Tera Guru

Hi Keerthi,



You can create a 'Wait for Condition' Activity and can write below condition to check if all the tasks are getting closed completed or not.



answer = true;


var grCatTask = new GlideRecord('sc_task');


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


grCatTask.query();


while(grCatTask.next()){


      if(grCatTask.state != 3){   // check if the state of TASK is not closed


      answer = false;  


      }


}



Once every task is closed, then the RITM/REQ can be closed accordingly.



Regards,


Suresh D


Mohit Yadav
Tera Expert

Hi Keerthi,



You can also refer to below link for better understanding & use of Wait for condition:



http://wiki.servicenow.com/index.php?title=Condition_Activities#gsc.tab=0



Navigate : Wait for Condition.



If helpful, please mark accordingly.



Thanks & Regards,


Mohit


Ajai S Nair
Giga Guru

Hi Keerthi,



As already mentioned by Suresh , you can query with RITM and state


or


You can also query by using the 'active' field on sc_task by giving the below code in the wait for condition,



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;


}