How to remove multiple attachment

Saridha_L1
Tera Expert

Hi Team,

Can anyone help me,How to remove multiple attachment from 2 tickets.

Regards,

Saridha.L

1 ACCEPTED SOLUTION

Gowrisankar Sat
Tera Guru

Use this script to remove all attachments:


var attachment = new GlideSysAttachment();  


var agr = attachment.getAllAttachments("<table_name>" <record_Sys_id>");


//example:   var agr =attachment.getAllAttachments("incident","7123398d4f317a048d853d828110c731");


while(agr.next()) {  


attachment.deleteAttachment(agr.getValue("sys_id"));  


}  


View solution in original post

8 REPLIES 8

Saridha_L1
Tera Expert

Hi, Thank you for your response.



There are10000+ attachments in 2 tickets,but there is no option to select all in manage attachments.


Please help.



Regards,


Saridha.L


In your case it might be better to run script that will delete all attachments for needed record.



For Example,


if you have Incident record with multiple attachments and you know sys_id(lets say sys_id == 'incidentID') of the incident,


script will look like this:



var gr = new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id','incidentID'); // selecting only records that belong to our incident


gr.addQuery('table_name','incident');


gr.deleteMultiple();


Gowrisankar Sat
Tera Guru

Use this script to remove all attachments:


var attachment = new GlideSysAttachment();  


var agr = attachment.getAllAttachments("<table_name>" <record_Sys_id>");


//example:   var agr =attachment.getAllAttachments("incident","7123398d4f317a048d853d828110c731");


while(agr.next()) {  


attachment.deleteAttachment(agr.getValue("sys_id"));  


}  


tvani
Tera Contributor

Easier way of deleting attachments is via method deleteAll.

 

var attach = new GlideSysAttachment();

 

attach.deleteAll(recordGR);

 

Please refer to the conversation Remove attachments using GlideSysAttachment