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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your inbound email action is on which table?

are you creating RITM from some custom logic?

Regards
Ankur

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

yes, its on sc_req_item table. & of type record action

Hi,

so it is of type Reply or New?

If new RITM is created then how is SC Task created? at that place only you can add code for attachment

you can query sc_task for the RITM and then copy

var gr = new GlideRecord("sc_task");
	gr.addQuery("request_item", current.sys_id);
	gr.query();
	while(gr.next()) {
		GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', gr.sys_id);
	}

Regards
Ankur

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

I have created a workflow to create sc_request,sc_req_item & sc_task , and called it in Inbound action. its for new mail only