Remove attachments using GlideSysAttachment

janpost
Kilo Contributor

Is it possible to remove attachments by using GlideSysAttachment? I'm looking for a function similar to GlideSysAttachment.copy(...), something like GlideSysAttachment.remove(...) or GlideSysAttachment.delete(...). If there is such a function where is it documented?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you want to remove all attachments from the record, you can use the following where recordGR is the gliderecord representing the record from which you want to remove attachments.



var attach = new GlideSysAttachment();


attach.deleteAll(recordGR);


View solution in original post

15 REPLIES 15

Joe Wilmoth
ServiceNow Employee
ServiceNow Employee

Hi. You should be able to call any JavaScript method on a record if you build the query correctly.


amadosierra
Kilo Guru

There is an Script Include named AttachmentAjax that can be called from a Client Script using GlideAjax to perform several attachment related tasks like: list, delete, rename, etc.



GlideSysAttachment can be used to delete attachment as follows:


var attachment = new GlideSysAttachment();


var agr = attachment.getAllAttachments(<table_name>, <table sys id>);


while(agr.next()) {


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


}


Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you want to remove all attachments from the record, you can use the following where recordGR is the gliderecord representing the record from which you want to remove attachments.



var attach = new GlideSysAttachment();


attach.deleteAll(recordGR);


Hi Brad,



We have written an onSubmit client script to show an alert when the attachment character exceeds 100 chars. Suppose there are 2 attachments already attached to the record and I am trying to attach one more attachment to the same record.   If this current attachment exceeds 100 chars, i want to remove this from the record. How can I do this?