Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Copy attachment from sys_attachment

didierl
Giga Contributor

Hello,

I have a lot attachment on sys_attachment that I would copy on different KB Articles.

I made an On after script on my Transform who import the articles. But it doesn't work.

When I tried between two articles from kb_knowledge, it's works fine.

Do you have any ideas ? I already copy from sys_attachment to another table, but this time, it doesn't works..

Thanks

// log.info("source.u_attachment = " + source.u_attachment);

// GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');

var sysAttachment = new GlideRecord('sys_attachment');

sysAttachment.addQuery('file_name',source.u_attachment);

sysAttachment.query();

if(sysAttachment.next()){

log.info("copy attachment " + sysAttachment.sys_id + " on knowledge article " + target.number + " - " + target.sys_id);

GlideSysAttachment.copy('sys_attachment', sysAttachment.sys_id, 'kb_knowledge', target.sys_id);

}

target.update();

2 REPLIES 2

Ken_Michelson
Kilo Guru

GlideSysAttachment.copy() copies all attachments from one source record to another. Therefore if sys_attachment is your source record, you are trying to copy "attachements on an sys_attachment" record ... which I doubt has any. Your source table needs to be a record that HAS attachments.



-Ken


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee