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

UI Action that copies attachments from one record to another

JJG
Kilo Guru

Hello, 

I have a UI action that creates a new record in a new table, it then copies all of the old info and inputs it into the new record. However, I would like the attachments to transfer as well. How can I achieve this? 

Here is what I have so far:

var gr = new GlideRecord('x_utsll_candidate_candidate_tracking');

gr.first_name = current.first_name;
gr.email_address = current.email_address;
gr.last_name = current.last_name;

gr.insert();

 

How can I also transfer the attachments?

1 ACCEPTED SOLUTION

This worked for me:

var gr = new GlideRecord('x_utsll_candidate_candidate_tracking');

gr.first_name = current.first_name;
gr.email_address = current.email_address;
gr.last_name = current.last_name;

var sysID = gr.insert();


GlideSysAttachment.copy('x_utsll_candidate_candidate_outreach', current.sys_id, 'x_utsll_candidate_candidate_tracking', sysID);


var mySysID = current.update();
current.deleteRecord();

 

View solution in original post

11 REPLIES 11

Prateek kumar
Mega Sage

Please take a look at below:

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/script/useful-scripts/reference/...


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Is this also about different instances like your other question? Or is this on the same instance?

If same instance. Should the old records and old attachments be kept or are these removed later? Asking because you could also remap the attachments, in that not needed to copy them.

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

This is a separate question from the other one we are working on together. I need a script that finds the current records attachments and then copies them over to the new record.