Copy Attachment with out duplicates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2014 06:45 AM
Hi All,
I am trying to copy attachment from task table to request with out duplicates
can any one help me
thanks in advance
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2015 10:58 AM
After talking with an SC who tested it, the GlideSysAttachment.copy() simply clones the attachment over so it will double the storage space used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2015 11:28 AM
Not a best way to do it, but here is a work around that I am using. Might need to alter some code, but the method is there. It seems like it's working for me so far. This will delete all current attachments on the request and re-add the attachments from the catalog task table.
Business Rule
When: After - Insert
Table: Attachment [sys_attachment]
function onAfter(current, previous) {
var catalog = new GlideRecord('sc_task');
catalog.addQuery('sys_id', current.table_sys_id);
catalog.query();
if (catalog.next()){
var reqItem = new GlideRecord('sc_req_item');
reqItem.addQuery('sys_id', catalog.request_item);
reqItem.query();
if (reqItem.next()){
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', reqItem.request);
req.query();
if (req.next()){
deleteDuplicateAttachments(req.sys_id);
GlideSysAttachment.copy('sc_task', catalog.sys_id, 'sc_request', req.sys_id);
}
}
}
function deleteDuplicateAttachments(requestID) {
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sc_request');
gr.addQuery('table_sys_id', requestID);
gr.query();
while (gr.next()) {
gr.deleteRecord();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2015 11:37 AM
var call = new GlideRecord('new_call');
call.addQuery('sys_id', current.table_sys_id);
call.addQuery('transferred_to', '!=', '');
call.query();
if(call.next()){
var att = new GlideRecord('sys_attachment');
att.initialize();
att.file_name = current.file_name;
att.content_type = current.content_type;
att.compressed = current.compressed;
att.table_name = call.call_type;
att.size_bytes = current.size_bytes;
att.size_compressed = current.size_compressed;
att.table_sys_id = call.transferred_to;
var attRec = att.insert();
var attDoc = new GlideRecord('sys_attachment_doc');
attDoc.addQuery('sys_attachment', current.sys_id);
attDoc.query();
while(attDoc.next()){
var attDocCopy = new GlideRecord('sys_attachment_doc');
attDocCopy.initialize();
attDocCopy.sys_attachment = attRec;
attDocCopy.position = attDoc.position;
attDocCopy.length = attDoc.length;
attDocCopy.data = attDoc.data;
attDocCopy.insert();
}
}
This is the way I copied attachments on an existing call record over to incident. This is so the call records could live and the end user could simply refer to it when adding things.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2016 04:06 PM
How to copy only some selected attachments from incident table to email table. Can you help me with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 08:04 PM
Hey Mike, can you give more description on this BR? I am planning to do a 'New Call' <-> 'Sc_Request' <-> 'sc_req_item' tables and was thinking on the same lines...