shivakumarpatil
Mega Guru

Hi @Revanth111 ,

GlideSysAttachment.copy() may not work when sys_attachment is the source.
Please try using GlideSysAttachment.writeContentStream() as shown below—it should correctly add the attachment to your Data Source.

var attachmentSysId = this.getParameter('sysparm_attachment_id');
        var dataSourceSysId = 'a73774132f4c8710b456202bcfa4e3cc';
        var gsa = new GlideSysAttachment();
        var grAtt = new GlideRecord('sys_attachment');
        grAtt.addQuery('table_sys_id', dataSourceSysId);
        grAtt.query();
        while (grAtt.next()) {
            grAtt.deleteRecord();
        }
        //Copy New attachment to Data source and transfor it
        var grAttachment = new GlideRecord('sys_attachment');
        if (grAttachment.get(attachmentSysId)) {
            var grDataSource = new GlideRecord("sys_data_source");
            if (grDataSource.get(dataSourceSysId)) {
                
    var fileName = grAttachment.getValue('file_name');
                var contentType = grAttachment.getValue('content_type');
                var sourceAttachmentSysId = grAttachment.getValue('sys_id');

   gsa.writeContentStream(
                    grDataSource,
                    fileName,
                    contentType,
                    gsa.getContentStream(sourceAttachmentSysId));

            }
        }
 

View solution in original post