Delete User Profiles

harish11
Mega Expert

Due to a import glitch (Dont ask me how), 17000 completely blank user profiles have been created in Service Now.

Can anyone help with a client script / Business Rule to delete them please? Thank you.

Empty Users.jpg

4 REPLIES 4

randrews
Tera Guru

there are a couple of ways to do this.. the safe long way and the more hazardous faster way....



for safe and long... get a query that JUST shows these bad records and check the coumn to select all and from the bottom list drop down select delete...



in order to make this faster you may want to change your list preference to the maximum available then go find your preference and change it from whatever you selected to a bigger number say 250



this way y ou can see 250 of them on your list scroll through and make sure you have them all... and delete them 250 at a pop.....



the more dangerous way <and i rarely do this unless i have to> is to define a query that will find JUST those records... then in a background script go through finding the records and delete them in the loop using the rec.deleteRecord() command



i don't like deleting records with a back ground script unless you can THOROUGHLY test in a non prod environment because of the potential to wreck your database.


Mike Allen
Mega Sage

I would get the query right in the UI, like you have done, then right-click on the breadcrumb and copy the query.   I would then use background scripts to write:



var user = new GlideRecord('sys_user');


user.addEncodedQuery('<your copied query here>');


user.deleteMultiple();



This is more dangerous, but the quickest method.   Just make sure your encoded query is right, make sure you test it in sub-prod, and go for it.


my problem with doing this in a background script is i am assuming this is ONLY in the production environment and there is no way to test the script and see what br's are activated when you run it etc...



no matter how well thought out.. if you can't test in non prod i am VERY hesitant to run any background script in production because of the potential for the unintended consequences to take down your system.


You can export those records via xml and import them into sub-prod to test.