Delete sys_attachement record via script

JJG_SNOW
Mega Guru

I have a script in a privately scoped application that is supposed to delete a specific record from the sys_attachemt table, but for whatever reason it is not working. I confirmed that I have the proper cross-scope privileges to delete from the table, and the logs are showing the "INSIDE DELETE' message. The only issue is that it is not deleting the record.

 

Script:

 

 

var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_nameLIKEsys_data_source^table_sys_id=bfa85545db6c3110663e633fd3961979");
attachment.query();
if(attachment.next()){
	gs.info("INSIDE DELETE");
	attachment.deleteRecord();
}

 

 

 

Logs:

JohnGilmore_0-1691508604709.png

 

 

 

 

Cross-Scope Privileges:

JohnGilmore_1-1691508772339.png

 

 

2 REPLIES 2

Daniel Borkowi1
Mega Sage

Hi @JJG_SNOW , as attachment are more complexe and splitted in different tables I recommend to use the Attachment API to delete attachments. Try the deleteAttachment function of GlideSysAttachment.

 

Greets
Daniel

Please mark reply as Helpful/Correct, if applicable. Thanks!

Prince Arora
Tera Sage
Tera Sage

@JJG_SNOW 

 

Can youOpen the table of "sys_attachment" check "can delete" checkbox and try again!

 

 

I have tried in my PDI and it worked!!

 

PrinceArora_1-1691561927069.png

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.