Closing all task manually before moving to another state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 05:07 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 05:16 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 05:18 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 05:26 AM
Can u elabote ankur

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 05:19 AM
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.