Copying Attachments from Parent to Child

htank66
Kilo Contributor

Hello all,

I have a question on how to get all of the parent attachments onto the child automatically.  I currently have made a Business rule on the Parent table.

find_real_file.png

 

find_real_file.png

 

I feel like there is something obvious that I am missing.  Any help is appreciated.  Thanks in advance!

17 REPLIES 17

I have looked into the relationship option but I would really prefer not to make a related list.

I have also tried it with reversing the sourcetable and the destinationtable

and I have tried by adding the sys_ids... pretty much trying everything and nothing seems to be working...

sachin_namjoshi
Kilo Patron
Kilo Patron

You need to query change_task table first to find out sys_id of change task and then use below sample code

 

var donorTable = 'change_request';
var donorID = '2b6644b15f1021001c9b2572f2b47763';
var recipientTable = 'change_task';
var recipientID = '78e47fe94f31d200bf004a318110c7d4';

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

Regards,
SAchin

amlanpal
Kilo Sage

Hi,

 

You may refer this thread which was asked for similar requirement. 

https://community.servicenow.com/community?id=community_question&sys_id=636a83e9db5cdbc01dcaf3231f9619eb

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Rob Sestito
Mega Sage

Hello,

Not sure if you have something that works as needed since the thread is still open. So, I wanted to display what I have for doing this very thing (well, from HR Task table).

I have a UI Action that once clicked on by the Assigned To of an HR Task, it copies all attachments from the Parent HR Case.

find_real_file.png

 

GlideSysAttachment.copy(current.parent.sys_class_name, current.parent, current.getTableName(), current.sys_id);

current.update();
action.setRedirectURL(current);

gs.addInfoMessage("Attachments have been added!");

gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');


I am currently trying to see how to make this a selection rather than a one-off of copying ALL attachments. Sometimes from incoming emails, attachments can be part of someone's email signature which is annoying to be posted as an attachment.

Hope this helps - if you have a working solution, please let us know. And then if you could - close out this post.

Cheers!

-Rob