To copy attachments, use the server-side scripts. You can use one of the following ways:
Use the base64 object of the original attachment. Due to the specifics of the readBase64 method, the maximum size of the copied file is 10 Mb.
const attachmentRec = new SimpleRecord('sys_attachment'); attachmentRec.get('167654133500015741'); ss.info(`Original size bytes: ${attachmentRec.size_bytes}`); // Info: Original size bytes: 92414492 const attach = new SimpleAttachment(); const base64Value = attach.readBase64(attachmentRec.sys_id); const attachCopyId = attach.writeBase64( attachmentRec.record_document_id, 'copy_of_' + attachmentRec.file_name, base64Value, attachmentRec.mime_content_type ); if (attachCopyId) { attachmentRec.get(attachCopyId); ss.info(`/record/sys_attachment/${attachCopyId}`); // Info: /record/sys_attachment/167654428100399185 ss.info(`Copy size bytes: ${attachmentRec.size_bytes}`); // Info: Copy size bytes: 0 } |
Use the SimpleAttachmentService class. The maximum size of the copied file depends on the instance-wide limit that is specified in the max_file_size_upload system property.
const attachmentRec = new SimpleRecord('sys_attachment'); attachmentRec.get('167654133500015741'); ss.info(`Original size bytes: ${attachmentRec.size_bytes}`); // Info: Original size bytes: 92414492 const importSource = new SimpleRecord('sys_import_source'); importSource.get('167647710807446665'); // From Incident Import Source const docId = ss.getDocIdByIds(importSource.sys_db_table_id, importSource.sys_id); const attach = new SimpleAttachment(); const attachUrl = attach.getAttachmentUrlById(attachmentRec.sys_id); const simpleAttach = new SimpleAttachmentService(); const docID = ss.getDocIdByIds(importSource.sys_db_table_id, importSource.sys_id); const attachCopyId = simpleAttach.createAttachmentByUrl(attachUrl, docId, `Copy_of_the_${attachmentRec.file_name}`); if (attachCopyId) { attachmentRec.get(attachCopyId); ss.info(`/record/sys_attachment/${attachCopyId}`); // Info: /record/sys_attachment/167654472004676912 ss.info(`Copy size bytes: ${attachmentRec.size_bytes}`); // Info: Copy size bytes: 92414492 } |
Attachment links can be used for various purposes:
Apart from this, links can also be used to:
Attachment records can be public or non-public. The publicity of attachments affects whether an attachment link will have an expiration date.
The Public attribute on the Attachment form defines the publicity of attachments.
To generate attachment links, log in and use the relative link /attachments/${sys_attachment.sys_id} to download attachments. You can also use the getAttachmentUrlById(attachmentId) method to generate a link via the API. See the SimpleAttachments article to learn more.
Depending on the publicity of an attachment, two links can be generated. For example:
|