Close many catalog tasks via a bulk operation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 11:25 PM
My client has a 110 service catalog tasks open pending other work. One task is related to one requested item. The client needs to close complete all 110 catalog tasks without manually updating them and additionally adding a generic message into 'Additional comments' from the requested item followed by closing the task which will automatically close the requested item. Would would be the best approach to doing this
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2020 11:33 PM
We have an existing Business Rule that will close the Requested Items when the tasks are closed by the operators. Will setWorkflow() need to be disabled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2020 12:06 AM
Hi,
since you had asked for bulk update; that's the reason setWorkflow(false) has been used to avoid triggering any BR on update
If you want to close related RITM and Request as well through background script then include that as well in script below
updateTasks();
function updateTasks(){
try{
var rec = new GlideRecord('sc_task');
rec.addEncodedQuery('<yourQueryHere>');
rec.setLimit(5); // remove this once you test for 5 records
rec.query();
while(rec.next()){
rec.state = 3; // close complete
rec.comments = 'This task has been closed';
rec.setWorkflow(false); // to avoid triggering any Business rule on catalog task
rec.update();
var ritm = new GlideRecord('sc_req_item');
ritm.get(rec.request_item);
ritm.state = 3;
ritm.setWorkflow(false);
ritm.update();
var req = new GlideRecord('sc_request');
req.get(ritm.request);
req.state = 3;
req.setWorkflow(false);
req.update();
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
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
05-24-2020 10:45 PM
Is there any update on this? Is this question got resolved or you need some more assistance.
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
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
04-21-2022 10:14 PM