Copy attachment

KouassiP
Tera Contributor

Hello All , 

In a RITM , i have a field where i attached a file (XLS) ...

KouassiP_0-1764706678827.png

 

Could you please show me how i can copy this file to another table ?

I have tried this , but the file is attached in the activity , not in the attachment doc . 

 

var attachmentGR = new GlideRecord('sys_attachment');

attachmentGR.addQuery('table_sys_id', ritmSysId);

attachmentGR.query();

if (attachmentGR.next()) {

    var sa = new GlideSysAttachment();

    sa.copy('sys_attachment', ritmSysId, sys_class_name , ciLDZ );

}

KouassiP_1-1764706957396.png

 

KouassiP_2-1764706972526.png

 

 

3 REPLIES 3

VivekSattanatha
Mega Sage

If your source attachment is in RITM table then your source table should be sc_req_item instead of sys_attachment table.

var sa = GlideSysAttachment()

sa.copy(String sourceTable, String sourceID, String targetTable, String targetID)

 

Please refer this

https://developer.servicenow.com/dev.do#!/reference/api/zurich/server/no-namespace/c_GlideSysAttachm...

Amitra Bhunia
Giga Guru

Your cord should be :

var sa = GlideSysAttachment()

sa.copy('sc_req_item', sys_id of RITM, String targetTable, sys_id of target record)

I hope this help. Please mark it helpful/correct if it resolve your query.

 

Regards,
Amitra

PrashantLearnIT
Tera Sage

Hi @KouassiP 

 

You can refer this video to implement your requirements below: 

https://youtu.be/HZ1u2HWmORs?si=_P-DeKQTeuOem8K5