Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

copy or create attachment via script

Alon Grod
Tera Expert

Hi,

I have multiple attachment on specific records. I want using a business rule to copy only specific one of them to a different record so that this attachment will be on the target record but he will also still be on the source record together with the other attachments on the source records. How can I achieve that?

2 REPLIES 2

glideFather
Tera Patron

ahoy @Alon Grod,

 

could you possibly explain what do you mean "specific records"? it might vary from Task to Incident or from Knowledge Article to a Story...

 

Also, share your business rule/script for a review, this description is too abstract to help you

@glideFather 

I have multiple pdfs files on the source record(case record on slm_case table)

I want to copy only of them to a new sn_slm_case record

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

    if (current.u_supplier_local == 'ארץ') {
        var gr = new GlideRecord('sys_attachment');
        if (gr.get('744fc71f9fb8d71023126dd81224abae')) {
            var attachment = new Attachment();
            attachment.write(
                current.getTableName(),          // table of the record you attach to
                current.getUniqueValue(),        // sys_id of the record you attach to
                gr.getValue('file_name'),
                gr.getValue('content_type'),
                GlideSysAttachment.getBytes(gr)  // file content
            );
        }
    }

})(current, previous);