Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to archive/remove older versions of attachments on record without custom tables or Archive Rules

Anjan 2025
Tera Contributor

Hi, 

I am working on an attachment versioning requirement and need some architectural guidance.
Scenario:
We have a custom table named 'Author'. We use a custom "Generate" UI Action to dynamically generate a file and attach it to the record. If a user clicks the UI Action again, it creates a new version of the file and attaches it to the same record.
Requirement:
I need to automatically remove/delete the older versions of the file from the record and retain only the latest version.


Constraints:
We cannot create any new custom tables to store the history or old file bytes.
We cannot create an Archive Rule directly on the sys_attachment table (as ServiceNow natively blocks archiving on system/dependent tables).
Has anyone worked on a similar requirement before? How can I achieve this version control cleanly while staying within these constraints? Any code snippets or structural suggestions (e.g., using specific APIs, attachment table triggers, or out-of-the-box logs) would be greatly appreciated!
Thanks in advance!

1 REPLY 1

Ankur Bawiskar
Tera Patron

@Anjan 2025 

but what's the business use-case you are solving by maintaining the versions?

 

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