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

Ankur Bawiskar
Tera Patron
Tera Patron

@SK36 

how do you mean by empty records?

what script did you start with?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@SK36 

Unfortunately you didn't share answers to my questions.

Glad that you got the script.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

Hi, is this fix script or background script?