Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Prevent duplicate attachments when copying

Lisa Silvaroli
Tera Guru

I am using the below BR on the sys_attachment table to copy attachments added to sc_task to their parent RITM. 

(function executeRule(current, previous /*null when async*/) {
 
var id = current.table_sys_id;
  var gr = new GlideRecord('sc_task');
  gr.addQuery('sys_id', id);
  gr.query();
  if(gr.next()){
  var ritm = gr.request_item;	
  GlideSysAttachment.copy('sc_task', id, 'sc_req_item', ritm);
  }

})(current, previous);

I run into issues with the following scenario:

Attachment1 added to sc_task and copied to ritm

Attachment 2 added to sc_task and the BR copies Attachment1 & Attachment2 to ritm 

RITM ends up with Attachment1, Attachment1 & Attachment2. 

How can I get this BR to not copy a attachment that's already been copied?  

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Sharing few links as well if you wish to copy single file

Copy JUST a certain file type from one record to another

How to copy a single attachment?

Regards
Ankur

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