The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Close many catalog tasks via a bulk operation.

greenbean
Mega Contributor

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

 

8 REPLIES 8

greenbean
Mega Contributor

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.

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

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

@greenbean 

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

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

Ravi9
ServiceNow Employee
ServiceNow Employee

if its only 110 you can just use "update all" context menu option as well ! 

just select the right filter and use 

find_real_file.png