I want to delete the attachment of RITM if I delete the attachment from REQ. I have already used some code to copy attachments of RITM and REQ.

Mayank Gupta8
Tera Contributor

I had a requirement where I had to copy the attachments of RITM into REQ. And also If I delete the attachment from REQ the attachments from the respective RITM should also get deleted. 

I have applied some Business Rule but it is deleting the other attachments which are getting attached.

var gr = new GlideRecord("sys_attachment");
var req = new GlideRecord('sc_request');
if (req.get(current.table_sys_id)) {

gr.addEncodedQuery("table_name=sc_req_item" + "^file_name=" + current.file_name);

gr.query();

while (gr.next()) {

gr.deleteRecord();
}
}

Can somebody help with the code?

5 REPLIES 5

Hi,

the above BR is before delete and has nothing to do with your testing since it will run only on deletion and not when new file is added to RITM

You need to debug the use case

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader