Copy attachment from child to parent table

lexy
Kilo Expert

I want to copy attachment from child record to parent record. The parent record lives on parent table sn_customerservice_case. The child record lives on sn_customerservice_ref

This script is running on my Child table with the following conditions

1. Before

2. Insert/Update


 

Here is my script, but it's not working
    
    var gr= new GlideRecord('sn_customerservice_case');
    gr.addQuery('sys_id',current.sn_customerservice_case);
    gr.query();
    if(gr.next()){
        GlideSysAttachment.copy("sn_customerservice_ref",current.sys_id,"sn_customerservice_case",gr.sys_id);
    }
    gr.update();
    
   

1 ACCEPTED SOLUTION

lexy
Kilo Expert

The final solution that I used to get it to work:

 

Insert/Update

Async

Script:

GlideSysAttachment.copy("sn_customerservice_ref",current.sys_id,"sn_customerservice_case",current.u_case_number.sys_id);

//Case number = u_case_number: This is the reference field to the parent record

View solution in original post

4 REPLIES 4

Ishita Shrivast
Kilo Guru

Hi Lexy ,can you please tell me on which table you have written your BR?

Regards,

Ishita

Ishita Shrivast
Kilo Guru

Hi Lexy, if you have written this BR on your child table and you want to make an update on a related table then you should write After Insert /Update BR.

Hope this helps.

Regards,

Ishita Shrivastava.

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

best to do is to make your BR async for avoid any performance issue, as suggested also by Goran to the below thread, it will work:

https://community.servicenow.com/community?id=community_question&sys_id=e8c103a9db98dbc01dcaf3231f96...

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

lexy
Kilo Expert

The final solution that I used to get it to work:

 

Insert/Update

Async

Script:

GlideSysAttachment.copy("sn_customerservice_ref",current.sys_id,"sn_customerservice_case",current.u_case_number.sys_id);

//Case number = u_case_number: This is the reference field to the parent record