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

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();

 

Mark Roethof
Tera Patron
Tera Patron

If not interested in keeping your old records:

Already to show you a bit what I'm after:

find_real_file.png

This is just a random sys_attachment record. You could actually simply update the table name and the sys_id, to your new table and new sys_id. Instantly the attachment is on that new record!

Now only scripted and... testing if this works fine for your ?scoped? app.

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