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

Aviv S_
Tera Contributor

Hi

can you share the solution?

SusanWinKY
Kilo Sage

Got this to work.  We have a bit more requirement...

1. Take the value of a field and create a TXT file out of it.

2. Put that TXT file into a "Field attachment" field on a form.

The attachment should not appear at the top of the form as a regular attachment.

 

I created an 'after' insert/update BR.  There may be a more elegant way to do it but this works.

(function executeRule(current, previous /*null when async*/) {

//Create an attachment from the CSR field
var attach = new GlideSysAttachment();
var currDateTime = new GlideDateTime();
var csr = current.getValue('csr');
var attachmentId = attach.write(current, "CSR-" + currDateTime + ".txt", 'text/plain', csr);

//Move the attachment to the Field Attachment field on the CERT form
var gr = new GlideRecord("sys_attachment");
var query = "table_name=sn_disco_certmgmt_certificate_task^sys_id=" + attachmentId;
gr.addEncodedQuery(query);
gr.query();
if (gr.next()) {
var currTableName = gr.table_name;
gr.table_name = 'ZZ_YY' + currTableName;
gr.update();
current.u_csr_attachment = attachmentId;
current.update();
}

})(current, previous);

 


Susan Williams, Lexmark