RITM to SCTASK attachment copy – duplicates and email attachments corrupted

RushikeshB24337
Giga Contributor

Good day, everyone. I hope you're all doing well.

I am trying to copy attachments from RITM to SCTASK using a Business Rule on sys_attachment (after insert).

Flow:

- User uploads files in portal → RITM created
- User sends additional attachments via email
- SCTASK is created

Issue:

1. Attachments are getting duplicated in SCTASK
2. Email attachments are getting corrupted in SCTASK (but work fine in RITM)

Implementation on BR on sys_attachment (after insert) with condition tablename = sc_req_item   
Script:- 

   var ritm = current.table_sys_id;
 
    var grSCTask = new GlideRecord('sc_task');
        grSCTask.addQuery('request_item', ritm);
        grSCTask.query();
 
        while(grSCTask.next()){
 
            var att = new GlideRecord('sys_attachment');
                att.addQuery('table_sys_id', grSCTask.sys_id.toString());
                att.query();
                att.deleteMultiple();
       
            GlideSysAttachment.copy('sc_req_item', ritm, 'sc_task', grSCTask.sys_id);
 
            // var gsa = new GlideSysAttachment();
            //  gsa.writeContentStream(
            //      grSCTask,
            //      current.file_name,
            //      current.content_type,
            //      gsa.getContentStream(current.sys_id.toString()));
        }    
})(current, previous);

What is the recommended way to copy RITM attachments to SCTASK without duplication and corruption (especially for email attachments).




8 REPLIES 8

Ankur Bawiskar
Tera Patron

@RushikeshB24337 

I will suggest not to copy the files as it will increase attachment table size

Instead you can show the attachments as related lists on form

check this

TNT: "Related Attachments" Related List 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hello @Ankur Bawiskar 

Thanks for the suggestion — this looks like a better approach 👍

Instead of copying attachments, showing them via related list will avoid duplication and storage issues.

I will try implementing “Related Attachments” on SCTASK.

Appreciate your help!

@RushikeshB24337 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@RushikeshB24337 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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