How to archive the attachments from sys_attachment table or how to delete the bulk attachments

Asish1
Tera Contributor

Hi,

 

How to archive the attachments from sys_attachment table or how to delete the bulk attachments.

 

 

Thanks,

Asish

 

7 REPLIES 7

siva krishna M2
Tera Guru

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

Hi @siva krishna M2 

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 

Sohail Khilji
Kilo Patron
Kilo Patron

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....

LinkedIn - Lets Connect

Jay Shah3
Mega Guru

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.