Carrying an attachment from one task to another in the same workflow

Blair5
Tera Guru

Is there a way to copy an attachment from one task to another in the same workflow? I saw this post: Copying attachments from an SC Item to the coressponding approval record for that item , but I'm hoping I can somehow use the scratchpad to do this. Is that possible? Any suggestions are greatly appreciated! Thanks.

14 REPLIES 14

Glad I could contribute something useful to the discussion!


This works great! I had to reconstruct the anchor tag but overall pretty slick!


Thanks,


Jeff


Yeah, it looks like the community forum automatically converted the html tags that were included in the original reply.


In any event, I'm glad that solution is working for you!


Mike McCall
Giga Guru

I've adapted this from a different script, so I apologize for any errors, but you should be able to include this in the "Advanced script" section of a Catalog Task activity within your workflow:



// Get all attachments.
var grAttachments = new GlideRecord('sys_attachment');
grAttachments.addQuery('table_sys_id', current.sys_id);
grAttachments.query();
var vAttachmentSys_id = '';

// Loop through all attachments.
while (grAttachments.next()) {
// Prep the primary attachment record.
grAttachments.table_name = 'sc_task';
grAttachments.table_sys_id = task.sys_id;

// Find all secondary attachment records.
var grAttachmentDocuments = new GlideRecord('sys_attachment_doc');
grAttachmentDocuments.addQuery('sys_attachment', grAttachments.sys_id);
grAttachmentDocuments.query();
// Duplicate the primary attachment record.
vAttachmentSys_id = grAttachments.insert();
// Loop through all secondary attachment records.
while (grAttachmentDocuments.next()) {
// Duplicate the current secondary attachment record.
grAttachmentDocuments.sys_attachment = vAttachmentSys_id;
grAttachmentDocuments.insert();
}
}

This script will copy the attachments of the parent requested item (assuming that your workflow runs against that record). If you want to pull the attachments from another catalog task or any other record, then you'll just need to find a way to get at the sys_id of the desired record, then use that value in this line:


grAttachments.addQuery('table_sys_id', current.sys_id);


GlideSysAttachment.copy('sys_attachment', '665e6f0a4fa31200c233eb118110c712', 'sys_data_source', 'd3fbec214f231200c233eb118110c7da');




Is it possible to copy attachment from attachment table to some other table?