Alternate way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I am in a domain separated instance and this
var copyAtt = new GlideSysAttachment();
copyAtt.copy(sourceTable, sourceSysId, targetTable, targetSysId);
this thing doesnt work in domain separted instance is there any other way to use gliderecord to achieve what this funtion does?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
There may be several ways to do it. The following is not tested but may be a starting point to not use the .copy() which may be failing.
function copyAttachments(sourceTable, sourceSysId, targetTable, targetSysId) {
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', sourceTable);
grAttachment.addQuery('table_sys_id', sourceSysId);
grAttachment.query();
while (grAttachment.next()) {
// Get the attachment data
var sa = new GlideSysAttachment();
var attachmentBytes = sa.getBytes(grAttachment);
// Create new attachment for target record
var newAttachment = new GlideRecord('sys_attachment');
newAttachment.initialize();
newAttachment.table_name = targetTable;
newAttachment.table_sys_id = targetSysId;
newAttachment.file_name = grAttachment.file_name;
newAttachment.content_type = grAttachment.content_type;
var newAttachmentId = newAttachment.insert();
// Write the bytes to the new attachment
sa.writeBase64(newAttachment, attachmentBytes);
}
}
// Usage
copyAttachments(sourceTable, sourceSysId, targetTable, targetSysId);
