How to copy a attachment to a file attachment field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 06:18 AM
I have a workflow that copies attachments from sc_req_item to a especific table where there is a file attachment field.
Looking at the attachment table, it creates the sintax zz_yytable_name, in the script I did this, but its not showing in the record:
copy_attach.copy(current.getTableName(), current.sys_id, 'ZZ_YYu_documentos_facilitadores', idDo
here is the record that was copied in attachment table:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 06:40 AM
Hi Juliana,
To rename your attached file, you can write an After business rule on sys_attachment table, query the attached record, and update the file name.
Also the following community thread may be helpful : Renaming attachments during upload
Mark if correct/helpful.
Regards,
Ajay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 06:51 AM
I don't need to rename the attachment, I need the attachment to appear in the respected field in my custom table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2018 07:03 AM
Hi,
Check below script :
var name = '';
var attachment = new GlideRecord('sys_attachment');
attachment .query();
while (attachment .next()) {
var name = attachment .file_name.toString();
}
var gr = new GlideRecord("custom_table");
gr.addQuery("sys_id","sys_id_of_record");//provide sysid of record where name is to set
gr.query();
if(gr.next())
{
gr.setValue("custom_field",name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 06:27 AM
Manged to make it work, it was missing to set the value in the field column