Copy Attachment from RITM to Catalog Task using Workflow Activity

Arun J
Kilo Contributor

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

1 ACCEPTED SOLUTION

Ankush Jangle1
Kilo Guru

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

View solution in original post

7 REPLIES 7

Jaspal Singh
Mega Patron
Mega Patron

You can use below in the Catalog task activity of workflow.

GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sc_task', task.sys_id);

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

Pranav Bhagat
Kilo Sage

var sourceSysID = '9c573169c611228700193229fff72400';

 

var targetSysID = '9d385017c611228701d22104cc95c371';

var copyAtt = new GlideSysAttachment();

copyAtt.copy('incident',sourceSysID, 'incident',targetSysID);

 

Pranav

AbhishekGardade
Giga Sage

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

Thank you,
Abhishek Gardade