Add attachment from Task to Change

JDickson
Kilo Expert

Hi all,

 

Is it possible to take attachments added to a Change_task and put them on the Change record itself? One of our workflow steps is to create a task for creating an estimate, as part of this it requires an attachment and then can be closed. I want that attached estimate to be added to the Change record itself once the task has been closed so that the customer can see it.

 

Kind Regards,

John

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

As your requirement is to copy attachment when the task is closed

Create a business rule on change_task with condition as state changes to closed

and use the following script

 

GlideSysAttachment.copy('change_task', current.sys_id, 'change_request', current.change_request);

View solution in original post

10 REPLIES 10

Harsh Vardhan
Giga Patron

yes thats possible,

you need to write the after business rule here, to copy the attachment form change task to your change record. 

 

adding one thread here, which has not applied on same table but the logic they have used same way you can do that. 

 

 

https://community.servicenow.com/community?id=community_question&sys_id=70305be5dbdcdbc01dcaf3231f96...

Brent Llewellyn
Mega Guru

I would suggest creating an async business rule that runs on sys_attachment when table name is change_task and add additional filters for any attachments that should not be copied

find_real_file.png

then add the script to get the Change Task and copy the attachments 

 

I tested this solution and it works but keep in mind that this will duplicate all attachments from Change Task to Change so if that is not the desired outcome you will want to add to the filter to look for the attachments you want copied. 

find_real_file.png

Thanks,

Brent

If this helps please mark as helpful or correct so that others may benefit from this information as well.

Hi Brent,

I have tried this business rule as you suggest but it does not copy the attachment. The task is created via workflow, then the attachment is added and the task closed. At this point i would like to take the attachment and add to the change itself. Is this something that could be done in a workflow?

 

Regards,

John

Absolutely. Add a script activity after the task and add this code.

// Get the tasks assosiated to this change
var changeTask = new GlideRecord('change_task');
changeTask.addQuery('change_request', current.getUniqueValue());

// filter for your specific Tasks
//changeTask.addQuery('') 
changeTask.query()

// Loop through each of the tasks
while (changeTask.next()) {

    // copy attatchment from Change Task to Change
    GlideSysAttachment.copy("change_task", changeTask.getUniqueValue(), "change_request", current.getUniqueValue());

}

Thanks,

Brent

If this helps please mark as helpful or correct so that others may benefit from this information as well.