How to Copy attachments from Parent to Child

Supriya25
Tera Guru

Hi All,

Kindly Suggest me solution to copy attahments. from Problem--> Incident

on Problem form we have one Check-box which names call it as "Copy Attachments " ,

it will be visible only when State | Root cause analysis .

if we make TRUE that check box, update the record , then copy all attachments from PROBLEM--> related INCIDENTS

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use after update BR on problem table

Condition: Checkbox Field [Changes To] True

Script:

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

	// Add your code here
	var gr = new GlideRecord("incident");
	gr.addQuery("problem_id", current.sys_id);
	gr.query();
	while(gr.next()) {
		new GlideSysAttachment.copy("problem", current.sys_id, "incident", gr.sys_id);
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Hi,

I agree with Paul here.

Not to duplicate the attachments on multiple table as it would consume more storage

alternative is to show related list

check this link for approach

Related Attachments" Related List

Regards
Ankur

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

Hi,

BR on sys_attachment is usually written to copy attachment as soon as it is added on some table and then you need to copy to another record

BR on parent table is required when some update would happen and then you want attachment to be copied over

Regards
Ankur

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

The SN Nerd
Giga Sage
Giga Sage

I don't think it is good practice to make copies of attachments across multiple records.

Consider instead creating Relationships that show attachments on records with relationships to the problem, or even a display BR that prompts the user that related records have attachments.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022