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

sachin_namjoshi
Kilo Patron
Kilo Patron

you will have to query sys_attachment table and then delete attachments.

 

Regards,

Sachin

Hi Sachin, do you have an example?

Please see below code

 

var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_sys_id", current.sys_id); // sys_id is table_sys_id
	gr.addQuery("file_name", current.start_at);// update file name as per your instance config
	gr.query();
	while(gr.next())
		gr.deleteRecord();
}
	

Thank you Sachin, works perfectly