Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

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

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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

20 REPLIES 20

Hi @Ankur Bawiskar ,

I have used similar code to copy attachments from SC Task to RITM table but the problem is the attachments in the sc task are from "Attachment" variable.

So, instead of 

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

I have used

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

 

Now, attachment is getting copied from sc task to activity stream of RITM but not to the paperclip icon on the header. I want that to be attached to paperclip on the RITM table. Do you have any suggestions on this?

Also, I don't see the attachment variable on the sc task once the task is closed complete, it would be good to have it on the task even it's closed. 

 

FYI - we are currently on Paris version and the catalog item is in a scoped application.

 

Thanks,

Kat

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  ||  ✨ 10x 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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader