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
08-12-2020 01:06 AM
Hi
can you share the solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2021 02:21 PM
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