Script to mass close cases

Rylie Markle
Tera Contributor

We are trying to mass close all cases of a certain HR Service type. We'd like to move any case for this HR Service that is still active to a Closed Complete state. Would a scheduled job be the best way to do this? Or is there another way?

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Rylie Markle 

 

Use flow designer, low code/ no code.

 

Trigger

Schedule

Action

Look up records

Update record

 

and work done.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Thank you! This is what I have so far- am I on the right track?

RylieMarkle_0-1719244232254.png

 

Sandeep Rajput
Tera Patron
Tera Patron

@Rylie Markle You can write a fix script to close such cases in bulk. Here is an example script which you can use.

 

Screenshot 2024-06-20 at 8.28.17 PM.png

 

Here is the script.

 

var glideHRCase = new GlideRecord('sn_hr_core_case');
glideHRCase.addEncodedQuery('hr_service=6628cde49f331200d9011977677fcf0b^active=true');
glideHRCase.query();
while (glideHRCase.next()) {
    glideHRCase.setValue('state', '3'); //3 Closed complete
	glideHRCase.setWorkflow(false);
	glideHRCase.update();
}

 

In this script replace 6628cde49f331200d9011977677fcf0b with the sys_id of your HR Service.

 

Hope this helps.