The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to delete empty records from user table using any script?

SK36
Tera Contributor

hi

I want to delete empty records from user table. How to achieve this by using script?

 

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @SK36 ,

I'm considering here username as empty. You may have different field. apply query according to that.

var gr = new GlideRecord('sys_user');  
gr.addEncodedQuery('user_nameISEMPTY'); // user_nameISEMPTY     if user id field is empty and people id filed is empty
gr.query();  
while (gr.next()) {  
  gr.deleteMultiple();
}  

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

5 REPLIES 5

You can use both the ways. 

Either in fix script or in background script. But if more records e.g. more that 500+ then go with fix script.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy