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.

How to copy attachment from sctask to ritm

Praveen94
Kilo Contributor

How to copy attachment from sctask to ritm

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Praveen,

I assume you want attachment to be copied over from SC Task to RITM when attachment is added

sample BR on sys_attachment; It would be copying all attachments to RITM from SC TASK

BR: after insert on sys_attachment

Condition: current.table_name == 'sc_task'

Script:

var taskRec = new GlideRecord('sc_task');

taskRec.addQuery('sys_id', current.table_sys_id);

taskRec.query();

if(taskRec.next()){

var ritmRec = new GlideRecord('sc_req_item');

ritmRec.addQuery('sys_id',taskRec.request_item);

ritmRec.query();

if(ritmRec.next()){

GlideSysAttachment.copy('sc_task', current.table_sys_id, 'sc_req_item', ritmRec.sys_id);

}

}

Regards
Ankur

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

View solution in original post

19 REPLIES 19

hi Ankur, 

what is the table in the BR configuration? and what is the filter condition? thanks!!

@Pato_Herrera 

can you post a new question for this and tag me there and share all the details as this is an old thread?

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

Hi!
This BR works well, but as you said, it would be copying all attachments from the SC Task to the RITM. So, if I add multiple ones, there are going to be duplicate attachments on the RITM.
Is there a way to copy only the newly added attachment, or do I have to create another BR to remove duplicate attachments?

@Clement_V 

Can you post a new question with all the details and tag me there as this is an old thread?

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

Hi @Ankur Bawiskar 

 

The problem I'm having is that all attachments are copied from the SCTASK to the RITM. This means that every time I add something to the SCTASK, duplicates are created on the RITM.


If I add document 1 to the SCTASK, I get document 1 on the RITM. Now, if I add document 2 to the same SCTASK, I get document 1 twice and document 2 on the RITM.


I have a rule that prevents duplicates, but it's based on the 'table_sys_id'/'table_name'/'file_name'/'content_type'/'size_bytes' fields, which isn't perfect.


I'd like to copy only the newly added attachment to avoid any duplicates from the start. Do you know of a way to do this?