Need help to copy attachment from Child case to Parent case

VShine
Mega Guru

Hello Experts,

We have special use case where we have Parent & child case stored in same HR table. 

I need to copy attachment from child case (hr performance case table) to parent case (on HR performance case table).

I see multiple community posts where copy from one table to another. But I couldn't find help on copying attachment from one record to another on same table.

1 ACCEPTED SOLUTION

Hi @vikrami 

You have to apply the logic such a way that this BR should run only once so it will copy once.

Question, When do you want to copy attachment ? which event ?

 

View solution in original post

8 REPLIES 8

rahulpandey
Kilo Sage

Hi Vikrami,

Below example script(replace with your table and applicable sys_ids) will work on same table record too. 

GlideSysAttachment.copy('sn_hr_core_case_operations','sys_id','sn_hr_core_case_operations','sys_id');

 

Please mark answer correct, if it helps.

@rahulpandey Sys ID for the records will be different everytime. How can I get sys ID for parent & child case dynamically?

Also, shall I use this script as BR?

Yes,

Use this in after BR. example  considering sn_hr_core_case_operations is table and parent column is column of parent.

GlideSysAttachment.copy('sn_hr_core_case_operations',current.sys_id.toString(),'sn_hr_core_case_operations',current.parent.sys_id.toString());

Ankur Bawiskar
Tera Patron
Tera Patron

@vikrami 

Parent HR details are stored in parent field so you can use this

To copy from child to parent

GlideSysAttachment.copy('performance table', current.sys_id, 'performance table', current.parent);

Regards
Ankur

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