Script to clear all user's email

Tona26
Tera Contributor

Hi, I just have cloned our production instance into a dev instance but, we need to clear all the data that lives on the email field from all the users at the user table

 

How can we do that?

 

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Tona26 ,

 

You can make use of Data Management module which requires no scripting to update/delete record in servicenow.

 

Just go to ur user table apply proper filter which gives u the exact records for which u want to empty the email address field. Once done right click on any column n scroll down u should see data management option where u can select update all with preview.

 

Once u select that one data management record will be created with ur filter applied. You just need to add one field for email as email empty save it n execute it. All email addresses will disappear.

 

Benefit of using data management module. If u want to revert back changes u will be able to rollback by going into that record under data management module. This requires no scripting

 

Thanks,

Danish

 

View solution in original post

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi, is there a reason you need to do this, the data is still within your SNC environment, with the same access controls and protections as production, and sub-production instances do not send emails except to clearly defined individual accounts.
How cleansed does the data need to be? do you also need to purge email records from cmn_notif_device ?

Hi, we need to clear the info because an external team is going to work on the environment, for security purpose we can't let them know some info that users have

How secure do you need to be?
You can run a background script against sys_user table to clear the email field, and another against cmn_notif_device to delete the notification device records that contain email address, but emails may still be accessible in parts of platform is someone goes looking for them.

What level of access will these external users have?
ACL's to hide the fields might be just as easy to implement and will mean that you still have your reference data - if it is required for BAU internal work?

 

I would also hope that your external contractors have been vetted and are subject to NDA's while working in your instance. 

AshishKM
Kilo Patron
Kilo Patron

Hi @Tona26 ,

Your should have at least one non-prod mail box within the org and configure that email with Dev/Test instance. 
Your can disable the emails send and receive property ( checkbox ) or you can route all emails to your org mailbox.

If you still need the script , write Fix Script because you need it again on next clone. 

 

Let us know if you need code. 

 

Note: You can ask your org office365 team to enable non-prod mailbox data cleanup policy, so you don't need to delete those non-prod email manually.

 

-Thanks

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution