How to copy a attachment to a file attachment field

Juliana
Kilo Expert

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

find_real_file.pnghere is the record that was copied in attachment table:find_real_file.png

6 REPLIES 6

Ajaykumar1
Tera Guru

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

I don't need to rename the attachment, I need the attachment to appear in the respected field in my custom table.

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);
     }

Juliana
Kilo Expert

Manged to make it work, it was missing to set the value in the field column