Fix script for deactivating HR services in bulk

sri vijaya
Tera Contributor

Hi 

we have a requirement to deactivate HR services in bulk(320) , so we need to create fix script for this

The conditions were : the table should be in employee relations case and topic category is one of "audit","tracking" and so on..(many topic categories)

Like if the service is from employee relations table and topic category is one of the given, the respective HR services should be inactive

Please suggest me if this is possible and if its possible  please help me with fix script

@Dr Atul G- LNG @AndersBGS @Mark Manders 

@Danish Bhairag2 

 

2 ACCEPTED SOLUTIONS

Danish Bhairag2
Tera Sage
Tera Sage

Hi @sri vijaya ,

 

if those filters can be applied manually on the table then it is doable without scripting. What u can do is after applying filter u can Right click on any column n select Data Management option where u will get 2 more options:

  1. Delete all with preview
  2. Update all with preview

Select update all with preview. It will open up a data management record for u with applied filter. under field u can select the respective field which u want to update for eg active n set it to false. 

once done & saved click on execute now. This will update all records from the list view for which u applied the filter in 1 go without any script.

 

Thanks,

Danish

 

View solution in original post

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sri vijaya 

 

NO need to do with script. Filter the results on list view and update in on go by Update all.

 

Expert @Danish Bhairag2  already provided a quick way. 

*************************************************************************************************************
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]

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

View solution in original post

4 REPLIES 4

James Chun
Kilo Patron

Hey @sri vijaya,

 

It's just 320 records, surely you can just update them in bulk on the list view?

That should take a couple minutes or so.

 

Cheers

Danish Bhairag2
Tera Sage
Tera Sage

Hi @sri vijaya ,

 

if those filters can be applied manually on the table then it is doable without scripting. What u can do is after applying filter u can Right click on any column n select Data Management option where u will get 2 more options:

  1. Delete all with preview
  2. Update all with preview

Select update all with preview. It will open up a data management record for u with applied filter. under field u can select the respective field which u want to update for eg active n set it to false. 

once done & saved click on execute now. This will update all records from the list view for which u applied the filter in 1 go without any script.

 

Thanks,

Danish

 

Lesiba Kgomo
Tera Contributor

Try:


var topicCategories = ["audit", "tracking", /* add more topic categories as needed */];

// Query Employee Relations Case table to identify records meeting the conditions
var caseGr = new GlideRecord('table_name'); // Replace 'table_name' with the actual table name of Employee Relations Case
caseGr.addQuery('topic_category', 'IN', topicCategories);
caseGr.query();
while (caseGr.next()) {
// Update HR service associated with the current case to set it as inactive
var hrServiceGr = new GlideRecord('hr_service_table'); 
hrServiceGr.addQuery('case', caseGr.sys_id); // Assuming 'case' is the reference field linking HR service to Employee Relations Case
hrServiceGr.query();
while (hrServiceGr.next()) {
hrServiceGr.active = false;
hrServiceGr.update();
}
}

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sri vijaya 

 

NO need to do with script. Filter the results on list view and update in on go by Update all.

 

Expert @Danish Bhairag2  already provided a quick way. 

*************************************************************************************************************
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]

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