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

Chuck Tomasi
Tera Patron

Hi Allu,



I recommend putting a condition on the Implement button to check if all child tasks are complete before that button displays.



This means two things need to be updated:


  • Condition statement needs to call a function
  • The function needs to be written


Condition statement on the UI action should include something like this... keep in mind this code is not tested in any way and may need modifications to run in your environment.



Condition: (existing statement) && allChildTasksClosed(current)



next, create a script include. (System Definition> Script Include)



Name: allChildTasksClosed


Script:



function allChildTasksClosed(chg) {


        var parentID = chg.getValue('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 no active requests were found, then return true (all child tasks are closed)


        if (count == 0) {


                  return true;


        }



        return false;


}


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Allu,



Query the change task table with the change request sys_id and check are there any task which are not in closed complete. If any open task is present don't submit the ui action i.e. do not execute the current.update() line of code.



Mark my reply as Correct and also hit Like and Helpful if you find my response worthy.


Thanks


Ankur


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

Can u elabote ankur


Mujtaba Amin Bh
Mega Guru

You can write your logic in the UI Action Implement itself. Do a glide record to check if any tasks for this change are open. If yes, then show some error message to the user.