Close hung Requests without sending out email

chrisn_
Mega Guru

Hello everyone,

Unfortunately a few of our key workflows were not done correctly. The tasks were closed and the RITM's were closed but the REQ's remain open. We now have 2100 REQ's that need to be closed and I would like to pick your brains for a method to do so without sending out the 2100 emails that ServiceNow will want to send. In the mind of the requester everything is complete so they are not waiting for any further word. Would this be possible with a scheduled job or do we need to do something drastic such as turn off email during off hours, close the REQ's and then clear the email that it creates before turning it back on?

9 REPLIES 9

Shashikant Yada
Tera Guru

I would suggest to deactivate the notification for sometime, if you do this then you don't need to delete the email logs.

Also to close the 2100 requests, you need to create the Scheduled job.

dandersonucare
Kilo Contributor

What I've done in the past is I've added a condition to the notification so it sends unless 'closed by = myself'. That way the notifications keep flowing normally, except for the junk I'm cleaning up.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

You should create a Fix Script that will loop through your records and mark them inactive and set the state appropriately.  Before your update you can use the setWorkflow(false) to prevent business rules, notifications, etc to not process by that update:

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-setWorkFlow_Boolean

The following blog article may be useful and also includes setWorkflow(false):

https://community.servicenow.com/community?id=community_blog&sys_id=60ccee25dbd0dbc01dcaf3231f961946

 

Please mark the post helpful or the correct answer to your question if applicable so others viewing can benefit.

Hi Michael,

I tried to get this script working in my sandbox and unfortunately it just closed everything as opposed to just the REQ's that had closed RITM's. Can you assist me in figuring out where I went wrong with this scheduled job?

closeREQ();

 

function closeREQ(){


var req = new GlideRecord('sc_request');


req.addQuery('active', 'true');


req.query();


while (req.next()) {

 

var ritm = new GlideRecord('sc_req_item');


ritm.addQuery('active', 'false');


ritm.addQuery('request',req.sys_id);


ritm.query();


if (ritm.hasNext()) {


//closeItem = false;


}


else {


req.state = '3';


req.active = 'false';


//req.comments = 'Closing REQ on account of all underlying RITMs marked Closed';


req.update();


}


}

 

}