The CreatorCon Call for Content is officially open! Get started here.

Copy attachments from one catalog task to another

Mishu
Tera Expert

I have 4 catalog tasks, I want to copy all attachments from Task 1--> Task 2---> Task 3 --> Task 4 ---> Task 5.

Wrote a Before insert BR on sc_task table with condition as Cat item is "ABC" and State is 'Open'

 

var task = new GlideRecord('sc_task');
task.addQuery('request_item',current.request_item);
task.query();
if(task.next()){
gs.addInfoMessage('Triggered');
GlideSysAttachment.copy('sc_task', task.sys_id, 'sc_task',current.sys_id);
}

It goes inside if condition but not copying attachment
How can i achieve this ?

6 REPLIES 6

Well, then my only response is this: TNT: The Customer is NOT Always Right

Ankur Bawiskar
Tera Patron
Tera Patron

@Mishu 

This will unnecessarily increase the attachment table size since same file will be replicated at 5 different places

you can do this if you still require this in before insert or after insert BR on sc_task

var task = new GlideRecord('sc_task');
task.orderByDesc("sys_created_on");
task.addQuery('request_item',current.request_item);
task.setLimit(1);
task.query();
if(task.next()){
	gs.addInfoMessage('Triggered');
	GlideSysAttachment.copy('sc_task', task.sys_id, 'sc_task',current.sys_id);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader