How to archive the attachments from sys_attachment table or how to delete the bulk attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 10:37 PM
Hi,
How to archive the attachments from sys_attachment table or how to delete the bulk attachments.
Thanks,
Asish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 10:48 PM
Hello @Asish1 ,
Use below code use in background script or fix script to delete bulk attachments
var attach = new GlideRecord('sys_attachment');
attach.addQuery('created','<','add your time');//this is optional and no need of you want to delete all attachment records
attach.query();
while(attach.next())
{
attach.deleteRecord();
}
if it helps kindly click on like icon and mark it as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 10:14 PM
Thanks much for your reply !! 🙂
we will try this..
I had a small doubt, if we permanently delete the attachments is there anyway does those deleted attachments will store in our instance, if yes again how can I restore those attachments.
Thanks,
Asish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 10:54 PM
Hi @Asish1 ,
You can navigate to sys_attachement table and apply filter conditon to retrive the attacements that you wish to delete. This can be based on size date tables etc.. You can delete it from the action menu given at the bottom > delete.
if not you can copy this fielterd list encoded query and use background script to delete the records from table. More on you can also use REST api explore also to delete the records...
I hope it helps... Wish you luck..
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 12:06 AM
For Archiving
Go to System Archiving -> Archive Rules -> New
Select Table and define condition like updated before 3 years ago (whatever is your requirement)
The table list over here doesn't have Attachment as option because attachments are linked to a record. Hence it has options to select table like incident, so when the incident record is archived, the related attachment record is also archived.