Copy attachment to Approval

Mike_R
Kilo Patron
Kilo Patron

In one of our workflows, we have a task and then an approval. I need help copying the attachment from the task to the approval so the attachment gets included in the approval email. Can anyone help me with the script?

1 ACCEPTED SOLUTION

mike275
Mega Expert

It's pretty easy to copy an attachment, you just need the original attachment's table name ('sys_task' in your case) and the sys id for the task (these are the first 2 arguments below). 

Then, the next 2 arguments are the table name and sys_id for the record you want to copy to:

 

new GlideSysAttachment().copy(originalAttachment.table_name, originalAttachment.table_sys_id, destinationTableName, destinationSysId);

View solution in original post

7 REPLIES 7

I tried this on the approval activity

 

new GlideSysAttachment().copy("sc_task", "workflow.scratchpad.taskid", "sysapproval_approver", current.sys_id);

I ended up using a business rule

 

(function executeRule(current, previous /*null when async*/) {


var gr = new GlideRecord('sc_task');
gr.addEncodedQuery("request_item.cat_item=bda2c072db4ca7c0f28289584b961926^request_item="+current.sysapproval.sys_id);
gr.query();
while (gr.next()) {
gs.log(gr.sys_id);

var taskid= gr.sys_id;
new GlideSysAttachment().copy("sc_task", taskid, "sysapproval_approver", current.sys_id);
}


})(current, previous);

You're passing in "workflow.scratchpad.taskid" which is a string, you probably want to do it without the quotes (workflow.scratchpad.taskid) so it will pass the actual task id in