- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 08:48 AM
Hi,
I am trying to create a button on the incident form which will delete all attachments currently on the incident. I am trying to do this as a UI action but am not having much luck.
I have put the button there and set up the permissions but can't seem to get the function to work. Could anyone advise if this is possible?
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 09:18 AM
Hi Garry,
Here is the optimized code you can use.
var attach = new GlideSysAttachment();
attach.deleteAll(current);
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 08:58 AM
You need to write code something like this to delete the records from attachment table.
var gr=new GlideRecord('sys_attachment');
gr.addQuery(table_sys_id', current.sys_id);
gr.query();
while(gr.next()){
gr.deleteRecord();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 09:00 AM
Hi Garry,
Here you go.
var gr = new GlideRecord('sys_attachment');
gr.addQuery(table_sys_id', current.sys_id);
gr.query();
while(gr.next()){
gr.deleteRecord();
}
http://wiki.servicenow.com/index.php?title=Delete_Duplicate_Attachments#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 09:05 AM
Hi Pradeep,
I have tried putting the below in a function so i can use it on the OnClick, but the button still does not seem to do anythuing.
Any ideas?
function removeAttachments(){
var gr=new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.query();
while(gr.next()){
gr.deleteRecord();
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 09:08 AM