Closing all task manually before moving to another state

asasas
Kilo Contributor

In change request i have following

I have IMPLEMENT UI Button, once it is clicked it will take to Review State

before moving to REVIEW state I need to closed all the task (created manually or from work flow). As you can see that The task is till pending showing above and State has moved to Review.

Please not : I want to make compulsary to user to closed all the task manually, not automatic closed.

Can some help me?

15 REPLIES 15

Put below code at the start inside function moveToReview().




var parentID = current.sys_id;  


      var count = 100;  


      var ctask = new GlideAggregate('change_task');  


      ctask.addAggregate('COUNT');  


      ctask.addQuery('change_request', parentID);  


      ctask.addQuery('active', true); // check how many active requests we have  


      ctask.query();  


 


      if (ctask.next()) {  


                  count = ctask.getAggregate('COUNT');  


      }  


 


      if (count != 0) {  


      addErrorMessage('Please close all open tasks for this change req');  


      return false;  


}


I put the above the in script. It is not working



When I am pressing button , It is not taking me anywhere, before it was taking to me other state


Can you post a full screen shot of your UI Action including the conditions?


111.PNG


112.PNG


I have removed your code and then taken screen shot because it was not working.


Ok. Here you go.



Step 1: Change Onlick to



chkOpenTasksAndMoveToReview();



Step 2:



Add following function in the script:



function chkOpenTasksAndMoveToReview(){


var parentID = current.sys_id;      


      var count = 100;      


      var ctask = new GlideAggregate('change_task');      


      ctask.addAggregate('COUNT');      


      ctask.addQuery('change_request', parentID);      


      ctask.addQuery('active', true); // check how many active requests we have    


      ctask.query();      


     


      if (ctask.next()) {      


                  count = ctask.getAggregate('COUNT');      


      }      


     


      if (count != 0) {      


      addErrorMessage('Please close all open tasks for this change req');      


      return false;      


}


else


{


moveToReview();


}


}