Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Need business rule to copy RITM attachments to respective sctask

bhupendrapareek
Tera Contributor
Hello , I need to have all the attachments of RITM showing to/ accessible from respective SCTASK as well (in Admin Workspace also). What are the possible ways to do it , and how can we do. Please Suggest. Advance Thanks,
4 REPLIES 4

johnfeist
Mega Sage

Hi,

 

The attachments are kept in sys_attachment.  However, what yo don't want to do is just create a process where you iterate through the attachments doing inserts.  Here is the code to take care of doing that copy task.  I expect that you will use it in an after insert business rule on sc_task.

var attachments = new GlideRecord("sys_attachment");
var task_attach = new GlideSysAttachment();
attachments.addQuery("table_name", "sc_req_item");
attachments.addQuery("table_sys_id", current.parent.sys_id);
attachments.query();
	
if (attachments.getRowCount() > 0) {
	attachments.next();
	task_attach.initialize();
	task_attach.copy("sc_req_item", attachments.table_sys_id, "sc_task", current.sys_id);
}

I copied this from a script that I use to copy attachments from incidents to change requests so there may be some fine tuning needed.

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Namrata Ghorpad
Mega Sage

Hi @bhupendrapareek ,

You can use below code in Business rule.

GlideSysAttachment.copy('sourcetable','sys_id','destinationtable','sys_id');

 

Please refer the below links.

 

https://www.servicenow.com/community/developer-forum/how-to-copy-attachments-from-ritm-to-taks/m-p/1... 

 

https://www.servicenow.com/community/now-platform-forum/copy-attachment-from-ritm-to-sc-task-on-requ... 

 

https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/script/useful-scripts/refere... 

 

If my answer resolves your issue then please mark it as correct and helpful.

Regards,

Namrata

Hi Namrata , 

i tried with below logic in "After BR" on sys_attachment table .but we are getting multiple-cloned attachments in sctask form for every sctask update (worknotes/add. comments) even though i have put restrictions in BR (yellow coloured) , still BR getting triggered , Any suggestions on that???

and second case is , for every attachment added on RITM ,  duplicate attachments are created on sctask.

please advise on it as well.

bhupendrapareek_0-1685716762941.png

 

Hi,

 

You need to have the rule as after insert on sc_task

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster