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

Hi Sumanth, the intent is to delete all ics files from the current Change request.  This will be a Business rule.  Per Sanchin, this should be the correct: 

gr.addQuery("table_sys_id", current.sys_id); // sys_id is table_sys_id

This is my current rule, does not work:

var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.sys_id); // 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();
}

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();
}