Blog

Search for Active Requests without items

Out of the box in ServiceNow, itil users or requestors can delete requested items.  This causes all kinds of communication and workflow issues.  One of those issues is that it leaves orphaned requests that don't get closed.

Here is a fix to this issue

1. Turn off the delete button for Requested Items

My suggestion is to turn off the ability to delete Requested items by non-admins.  

https://<your_instance>/sys_security_acl_list.do?sysparm_query=operation%3Ddelete%5Ename%3Dsc_req_item

2.  Run a script to find orphaned Requests

1. Elevate your privilege to security_admin.
2. In the Left Navigator > Scripts - Background
3. Paste this in the Run Scripts area:

findActiveRequestswithoutItems();
function findActiveRequestswithoutItems() {
var grRequest = new GlideRecord("sc_request");
grRequest.addEncodedQuery("active=true");
grRequest.query();
//gs.print('grRequest Query: ' + grRequest.getEncodedQuery() + ' = ' + grRequest.getRowCount());
gs.print('BAD REQUESTS, No Requested Items :(');
while (grRequest.next()) {
var grRequestedItem = new GlideRecord("sc_req_item");
grRequestedItem.addQuery("request",grRequest.sys_id);
grRequestedItem.query();
if(grRequestedItem.getRowCount() == 0) {
gs.print(grRequest.number);
}
}
}

4. Click Run Script
5. With the results from the script go find the orphaned Requests and close them

Thanks,
Mike