Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copy attachment form one task to another task

Shavi Dabgotra
Giga Contributor

Hello All !

How can I copy a attachment from one HR task to another HR task? 

Thank You 

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Depends on what/how/when/etc.. Though basic code for Server side scripting:

GlideSysAttachment.copy('table_source_record', 'source_sys_id', 'table_target_record', 'target_sys_id');

So for example:

GlideSysAttachment.copy('sn_hr_core_task', 'f94bf4c5dbc910505ed4a851ca96192e', 'sn_hr_core_task', 'a38951d03bd4481452ca655593efc4eb');

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Megha Padale
Giga Guru

Hi,

Refer this sample code:

var task = new GlideRecord('sc_task');

task.addQuery('request_item',current.request_item);

task.query();

if(task.next()){

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

}

If my answer helped you in any way, marked answer as helpful and correct.

Thanks and regards,

Megha.

 

AbhishekGardade
Giga Sage

#Copying an Attachment from One Table/Record to Anothet Table/Record:

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 = 'sn_hr_core_task';//

var donorID = '2b6644b15f1021001c9b2572f2b47763';

var recipientTable = 'sn_hr_core_task'; //

var recipientID = '78e47fe94f31d200bf004a318110c7d4';

GlideSysAttachment.copy(donorTable, donorID, recipientTable, recipientID);

 

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
ServiceNow MVP 2020

Thank you,
Abhishek Gardade

Here I have to take Donor table and recipient table are same i.e sc_task but short description of the tasks are different, how can query and copy the attachment from one task to another task.

Please suggest me once.

 

Regards

Panduranga K.