- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 02:17 AM
Hello All,
There is a requirement to copy the attachment from RITM to Catalog Task using workflow.
I could see more community answer to do that using after Business Rule in task form, but I have been asked to do that using workflow.
I tried replicating some of the scripts in the community using Run Script activity but that didn't help.
(GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);)
Can some help me please.
Thanks,
Arunkumar J
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 02:47 AM
Hello,
In the catalog task use this code this will help you
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sc_task', task.setNewGuid());
Mark it as Helpful/correct if it helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 02:22 AM
You can use below in the Catalog task activity of workflow.
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sc_task', task.sys_id);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 02:29 AM
In addition, copying/duplicating attachments is not an ideal option though its quite straight forward to implement but it can have some issues in long run when 'n' number of attachments gets stored in Attachment table.
In order to avoid this you can also follow blog & give a check which instead of duplicating simply creates a relationship that is used. Though the result is same but duplication of attachment is avoided.
Follow link for a check

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 02:24 AM
var sourceSysID = '9c573169c611228700193229fff72400';
var targetSysID = '9d385017c611228701d22104cc95c371';
var copyAtt = new GlideSysAttachment();
copyAtt.copy('incident',sourceSysID, 'incident',targetSysID);
Pranav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2020 02:25 AM
As suggested by other developers,
Copying all of the attachments associated with a given record is fairly straightforward. You simply call the copy method of the GlideSysAttachment class, and pass in four parameters:
- The table you want to copy the attachment from (incident, change_request, etc.).
- The sys_ID of the record you want to copy the attachment from.
- The table that you want to copy the attachment to.
- The sys_ID of the record you want to copy the attachment to.
This might look something like this:
var donorTable = 'sc_req_item';// table from where you are copying attachment
var donorID = current.sys_id; // sys Id of your RITM
var recipientTable = sc_task; // table where you want to copy
var recipientID =grTaskSysID // sys Id of your task
GlideSysAttachment.copy(donorTable, donorID, recipientTable, recipientID);
In your case, as youa are using in Runscript activty, you need to first find out for which sc_task you want to copy the attachment. Once you identified that replace your value in above grTaskSysID.
Your final script should be like below. I have written this script to copy attachment to all tasks. In case, if you want to add it specific task then just add new addQuery with your condition.
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.getValue('sys_id'));
grTask.query();
while (grTask.next()) {
var grTaskSysID = grTask.getValue('sys_id');
var donorTable = 'sc_req_item';
var donorID = current.sys_id;
var recipientTable = sc_task; //
var recipientID = grTaskSysID ;
GlideSysAttachment.copy(donorTable, donorID, recipientTable, recipientID);
}
Thank you,
Abhishek Gardade
Abhishek Gardade