Remove attachment from a change request

Dead Blade
Kilo Guru

Hello All, I am having difficulties removing iCalendar attachments from a Change Request.

I am aware of community post: Removing attachments using GlideSysAttachment

I may be using this wrong in a business rule.

var attach = new GlideSysAttachment();


attach.deleteAll(recordGR);

 

But further, can I only remove iCalendar attachments?

 

1 ACCEPTED SOLUTION

Dead Blade
Kilo Guru

This is the fix for this post:

Thank Sanchin and Sumanth for their guidance.

 

var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.sys_id); // sys_id is table_sys_id
gr.addQuery("content_type", 'text/calendar'); // file content type is text/calendar

gr.setLimit(5);
gr.query();
while(gr.next()){


gr.deleteRecord();
}

View solution in original post

11 REPLIES 11

I spoke too soon, it deletes all attachments.  How can I wildcard the attachments that I wanted deleted, example "Meeting_Invitewildcard" ?

Hi ,

 

Use filter condition based on content type contains calendar(your required format) and your table name and run the script:

add these lines in script:

gr.addQuery(' content_type', 'attachment format which you want to delete');

gr.setLimit(5);//test with 5 records and increase value if script works

 

 

 

Please mark it as helpful (or) correct if it fixes your issue

 

Thanks,

Sumanth

I added:

gr.addQuery('text/calendar',ics);
gr.setLimit(5);

 

It did not work.  It deleted all attachments.  1 pdf and 2 ics files, expected only the ics files to delete.

Hi,

If you want to delete all the ics files in sys_attachment table related to your table please use below script.

 

var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", put your table name here); // sys_id is table_sys_id
gr.addQuery("content_type", ics);// update file name as per your instance config

gr.setLimit(5);
gr.query();
while(gr.next()){


gr.deleteRecord();
}

 

If you want to delete only particular record attachments please use below script:

var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", put your record sysid(if it is change request , copy sysid of particular change request and paste it in this line)); // sys_id is table_sys_id
gr.addQuery("content_type", ics);// update file name as per your instance config

gr.setLimit(2);
gr.query();
while(gr.next()){


gr.deleteRecord();
}

Try this and let me know

 

Thanks,

Sumanth

 

Hi ,

Are you able to fix your issue.

If it resolved your issue please mark it as correct , it will help others who are looking for similar type of solution.

 

Thanks,
Sumanth