Need a fix script to close some corrupt HR cases
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 06:22 PM
Hello, I have a list of about 10 HR cases that are corrupt (give record not found error when trying to open). We think this was due to a poorly created inbound action which has since been addressed. However, now I would like to close the cases using a background script. So far, I have the below script, but it isn't working so I think it needs some tweaking. Thank you in advance!
Christina

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 03:52 AM
@Christina23 Please update your script as follows.
var gr = new GlideRecord('sn_hr_core_case_workforce_admin');
gr.addEncodedQuery('numberINHRC2477494,HRC2475136');
gr.query();
while(gr.next())
{
gr.state= '3'; //to close;
gr.update();
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 11:38 AM
Hi Sandeep! Thank you for your help. Unfortunately, the script is not working. It may be that the records are too corrupt. I did notice that the category and subcategories on these cases aren't populated which may be what is keeping them from closing. I'm not able to populate them in listview and can't open the cases (as the records are corrupt). Could we possibly add the category and subcategory through a script? If so, do you know what script I could use to do that? Thank you! Christina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:28 PM
@Christina23 try this script:
var encQuery = "HRC2477494,HRC2475136"; // encoded query should be placed here
var gr = new GlideRecord('sn_hr_core_case_workforce_admin');
gr.addEncodedQuery(encQuery);
gr.query();
gr.setWorkflow(false); // it will bypass BRs CS etc.
while(gr.next())
{
gr.state= '3'; //to close;
gr.update();
}
In case, the cases have related tasks then you'll need to close them first before closing the parent case.
For that, you can find here a script that could help you:
https://github.com/danybr0/servicenow-scripts/blob/main/servicenow-scripts.js

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 09:15 PM
@Christina23 Do you face any errors when you run this script? Did you check the system logs for any sign of error when this script runs?
Also, by category and subcategories were you referring to Topic Detail and Topic Category or you have custom category and sub category fields defined on your HR case table.
Regarding setting the fields via scrip, yes these fields can be set within the script.