deleteAll attachment function in GlideSysAttachment() in scoped app not available

rexter1
Tera Expert

hi guys, the below script:

 

var attachment = new GlideSysAttachment(); //Initialize GlideSysAttachment()
var grCase = new GlideRecord('sn_hr_core_case'); // GlideRecord along 'sn_hr_core_case' table
grCase.addEncodedQuery('numberSTARTSWITHHRC0001116');  
grCase.query();
while (grCase.next()) {
attachment.deleteAll(grCase); //Deleting all attachments
}

 

Drops an error  

Cannot find function deleteAll in object [object GlideSysAttachment].

 The same script with 'incident' table works well. So I suppose this deleteAll function is not available from scoped app? Do you know any workaround if we still can use GlideSysAttachment() deleteAll in scope? Many thanks! 

4 REPLIES 4

Basheer
Mega Sage

Hi @rexter1 

Instead of attachment.deleteAll(grCase), why don't you use deleteAttachment(string attachmentID)

 

No, because for that we would need to know the sys_id of the attachment.First we need to know from what cases we need to delete attachments (closed befoe X time) then fo to attachment tabel to delete. We can clearly delete the records with two glide records, one on HR case, 2nd on attachment, but we cant use  GlideSysAttachment(); deleteAll function, which would be much more better and clear.

Serghei Tolstov
Tera Contributor

Apparently attachment.deleteAll(gr) - is for Global, in scope it gives error as you mention.
to go around it use Global Script Include or Global Scheduled job,  

 
 
 

Sheldon  Swift
ServiceNow Employee

Hi @rexter1 - I expect you could try something like this to achieve the same:

 

var grCase = new GlideRecord('sn_hr_core_case');
grCase.addEncodedQuery('numberSTARTSWITHHRC0001116');
grCase.query();
while (grCase.next()) {
    var sysAttachment = new GlideSysAttachment();
    var attachmentGR = sysAttachment.getAttachments(grCase.getTableName(), grCase.getValue('sys_id'));
    while (attachmentGR.next()) {
        sysAttachment.deleteAttachment(attachmentGR.getValue('sys_id'));
    }
}