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

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

Hi,

you can also use flow designer with no script to copy all the attachments from current problem to related incidents

Regards
Ankur

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

Hey Ankur,

Thanks for reply,

 

i have seen most of BR script designed on "sys_aathcment" table.

i didn't understand one thing

1 . At which point we have to write BR on "Sys_attachment " table to copy attachments from Parent to Child ?

2. At which point we have to write BR on "Parent"  table to copy attachments from Parent to Child ?

 

Hello,

 

As mentioned by Ankur, the BR should run on "problem" table, WHEN your checkbox is made TRUE.

Then run the script provided inside that business rule