How to find any active requests that have all their requested items closed. This can occur due to not setting the Stage field in your Item workflows.
In ServiceNow there is an important Business rule called "Close Parent if Required". After each Requested Item is closed, it checks if all the related Requested Items are closed. If all of them are closed, the Request is closed.
If you don't use Stages properly in your workflow, such as not using them at all, this can cause the Request to not close.
You can fix this by adjusting your workflows to have stages. However to find all the existing Requests with this issue, you can run this script:
Find Active Requests with all Closed Requested Items
1. Elevate your privileges to security admin
2. In scripts - background run this script
findActiveRequestswithClosedItems(); function findActiveRequestswithClosedItems() { var grRequest = new GlideRecord("sc_request"); grRequest.addActiveQuery(); grRequest.query(); gs.print('BAD REQUESTS, No Active Requested Items :('); while (grRequest.next()) { var grRequestedItem = new GlideRecord("sc_req_item"); grRequestedItem.addQuery("request",grRequest.sys_id); grRequestedItem.addActiveQuery(); grRequestedItem.query(); if(grRequestedItem.getRowCount() == 0) { gs.print(grRequest.number); } } }
You can then use the results of this script to go out and close some requests.