How to Copy attachment from parent to child record

Sanket Pawar
Tera Contributor

Hi All,

I have a from on table u_cssc. whatever attachment is added in cssc record, that should be copied in incidents which are in related list of that record.

How can we achive this.

 

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @Sanket Pawar ,

You need to write a after insert Business rule on sys_attachment table and the condition should be like 

"Table name is u_cssc"

Screenshot 2022-11-29 at 16.48.13.png

script :

In the query i used parent field assuming parent is the field which stores the cssc record on the incident form.If not replace it with the field name which stores the cssc record 

(function executeRule(current, previous /*null when async*/) {

     var gr = new GlideRecord('incident');
	gr.addQuery('parent',current.table_sys_id); // assuming parent is the field  which stores u_cssc record
	gr.query();
	while(gr.next())
		{
			new GlideSysAttachment.copy("u_cssc", current.table_sys_id, "incident", gr.sys_id);
		}
})(current, previous);

Hope this helps 

Please accept the solution if it helps you 

Thanks

 

View solution in original post

4 REPLIES 4

Pavankumar_1
Mega Patron

Hi @Sanket Pawar ,

Refer below solution it will help you.

https://www.servicenow.com/community/it-service-management-forum/how-to-copy-attachments-from-parent...

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Hi @Sanket Pawar ,

My response will have the solution. Have you tried?

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

manducchau
Mega Guru

I don't think it's a good practice to copy attachment from one object to another object as you would imagine it will waste your licensed storage. There are several ways to achieve the visibility of the attachment, depending on your requirements.

 

There is an excellent ASK WHY article from Chuck here which you may rethink this.

Mohith Devatte
Tera Sage
Tera Sage

Hello @Sanket Pawar ,

You need to write a after insert Business rule on sys_attachment table and the condition should be like 

"Table name is u_cssc"

Screenshot 2022-11-29 at 16.48.13.png

script :

In the query i used parent field assuming parent is the field which stores the cssc record on the incident form.If not replace it with the field name which stores the cssc record 

(function executeRule(current, previous /*null when async*/) {

     var gr = new GlideRecord('incident');
	gr.addQuery('parent',current.table_sys_id); // assuming parent is the field  which stores u_cssc record
	gr.query();
	while(gr.next())
		{
			new GlideSysAttachment.copy("u_cssc", current.table_sys_id, "incident", gr.sys_id);
		}
})(current, previous);

Hope this helps 

Please accept the solution if it helps you 

Thanks