Need a fix script to close some corrupt HR cases

Christina23
Tera Contributor

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

 

var gr = new GlideRecord('sn_hr_core_case_workforce_admin');
gr.addQuery('number','HRC2477494','HRC2475136');    
gr.query();
if(gr.next())
{
 
   gr.state= 3; //to close;
   gr.update();
}
7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@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.

 

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

@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

@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.