I want to copy attachment from RITM to SCTASK record

Abhilash Janga1
ServiceNow Employee
ServiceNow Employee

I am trying to copy attachment from RITM to SCTASK record. I have written after-insert BR for that. its working when i submit the request by submitting the cat item. but to create RITM & SCTASK i have created one Inbound mail Action. its not working there. In the inbound mail action i have selected target table as "sc_req_item". So , the attachments coming from mail are getting attached directly to RITM record. but i want to copy the same attachments from the RITM to SCTASK record.

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

This is the code i am using for copying attachment. Please if you can help. where should i debugg?

1 ACCEPTED SOLUTION

@Koki 

Hope you are doing good.

Did my reply answer your question?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

 

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

View solution in original post

10 REPLIES 10

Hi,

then in the workflow to create sc_task you must be knowing the RITM sys_id because you must be linking that SC Task with RITM

there you use this script during creation itself

Can you share how are you creating SC_task from workflow? and workflow is running on which table?

once you know the RITM sysId you can use the script to copy attachments

Regards
Ankur

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

Hi Ankur,

I have created the workflow on sc_req_item table only. tried copy attachment code in create task, but not working. As i have selected target table as "sc_req_item" for inbound action, by default system is removing those attachments from the mail record & attaching them to RITM record. Is this affecting my logic?

Hi,

are you having attachments to RITM once inbound is processed?

Can you share script you are using in RITM workflow to copy attachment and are you using create catalog task activity?

where are you writing the copy script in workflow?

Regards
Ankur

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

Hi Ankur ,

Yes i am able to see the attachments on RITM when inbound is processed. So i have written after insert BR 

This the code written in BR=

 gs.info('Testing BR');
GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);
gs.info('Testing BR After'); 

 

I can see both info messages in log. but attachment is not copying

Hi,

so this BR is after insert on sc_task table

then the above script should work fine

try this

new GlideSysAttachment().copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);

Regards
Ankur

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