ServiceNow Cleanup Activity

Vaibhav Ramteke
Mega Contributor

Hi Community,

While reviewing attachments using sys_attachment.list, I found a large amount of data that appears to be unused and was created before December 2021.

Our ServiceNow instance was implemented around February–March 2022, so these attachments seem to pre‑date the instance onboarding and are not linked to any active business records.

I’m looking for guidance on the best and safest approach to clean up this data.


How I Identified Potentially Unused Attachments

So far, I have used the following checks to identify unused data:

  • Filtered sys_attachment records where:
    • sys_created_on < 2021-12-01
  • Reviewed attachments where:
    • table_name is empty or points to tables that no longer exist
    • table_sys_id does not have a matching record in the referenced table
  • Checked attachments linked to:
    • Deleted records
    • Inactive custom tables
  • Manually verified random samples to confirm they are not referenced anywhere in the UI

I would like to confirm whether this is a correct and complete approach, or if there are additional checks I should perform.


Questions for the Community

  1. What is the recommended way to confirm attachments are truly unused and safe to delete?
  2. Are there any out‑of‑box jobs, reports, or scripts to help identify unused attachments?
  3. Is it a best practice to:
    • Delete only from sys_attachment, or
    • Also clean up sys_attachment_doc?
  4. Are there any dependencies, logs, or audit requirements to consider before deleting old attachments?
  5. What precautions should be taken for production cleanup (backups, approvals, phased deletion, etc.)?

Any best practices, sample scripts, or documentation references would be greatly appreciated.

Thanks in advance!

2 REPLIES 2

Tanushree Maiti
Kilo Patron

Hi @Vaibhav Ramteke 

 

Check these artcle /post to find how to identify orphaned attachment:

Finding and deleting orphaned attachments 

Purge Orphan Attachments (custom solution and... Washington out-of-the-box!)

KB0995336 Attachments for potential deletion 

Orphaned ML Model Artifact attachment document records

 

Now for automated deletion ,you can go for Scheduled scripted execution :

 

Ref for code: Automatically Delete Attachments \

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Vaibhav Ramteke
Mega Contributor

Hi @Tanushree Maiti 
Thanks for your suggestions.