Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
How to avoid attachments from using up too much storage in attachment table when sending out daily report notifications - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • How to avoid attachments from using up too much storage in attachment table when sending out daily report notifications
KB0812599

How to avoid attachments from using up too much storage in attachment table when sending out daily report notifications


1005 Views Last updated : Jul 24, 2025 public Copy Permalink
KB Summary by Now Assist

Issue

Depending on business requirements, there can be a use case where significant number of Email reports need to be sent that have large report attachment files.

Over time, all those attachments will use up a lot of storage space in the database.

Here is automated solution that be implemented to flag some of those attachments for deletion without deleting attachments directly.

 

Cause

Please note that the suggestion proposed in this article adds on to the out of the box features documented below.

Data archiving / Email Retention plugin: Data archiving

Email retention: Email retention

Resolution

It is possible to delete Email records and their file attachments will cascade delete.

Here are some sample basic queries to get started with like:

target_table=NULL^typeINsend-failed,send-ignored,sent
OR
target_table=sysauto_report^typeINsend-failed,send-ignored,sent

Additional filter criteria should be used to avoid deleting wrong records such as :

  • date time interval
  • subject filter
  • keyword filter 

Here is a sample script that may be run as part of an automated scheduled job.


Please note that this is just an example, and it should be further extended and tested before, never run this in production without testing.

It would be worthwhile considering to add auditing so that records would only be flagged for deletion and their sys_id added to a temporary table and reviewed by and administrator before finally deleting them.

var gr = new GlideRecord('sys_email');
//No target table
gr.addEncodedQuery('target_table=NULL^typeINsend-failed,send-ignored,sent');
// sys_report table
// gr.addEncodedQuery('target_table=sysauto_report^typeINsend-failed,send-ignored,sent');

gr.query();
// Test row count, rowcount can impact performane if there are many.
gs.log(gr.getRowCount());
// Add conditions or auditing code here before deleting.
// Once you are sure, then delete with that code.
gr.deleteMultiple();

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.