How move attachments from one table table to another table

Kiran Kumar De1
Tera Contributor

Hello,

We will be using 2 different customized tables far attachment functionality and in future would like stop using one of them. Currently records have attachments and we are thinking to migrate existing attachments to another customized table so that we can use only one functionality effectively. Could you please someone to help on this to how to proceed with the migration without loosing attachments?

Thanks,

Kiran

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Kiran,

You can create a fix script/Background script to loop through records and then push attachments via GlideSysAttachment.

Copy attachments from record to record

Use the following script to copy an attachment from one record to another record:
GlideSysAttachment.copy('sourcetable','sys_id','destinationtable','sys_id');

Please refer https://snprotips.com/blog/2016/2/25/understanding-and-using-glideattachment#4

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

 

- Pradeep Sharma

Hi Kiran,

Let me know if that answered your question. If so, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list

 

- Pradeep Sharma

I know this thread is old but the GlideSysAttachment.copy function is very good, you just have to be careful how you use it.

 

If you loop through the records on the sys_attachment table this can cause issues of duplicate attachments on the target record as the loop can encounter the same source record twice.

 

Hi Pradeep Sharma,
 
from background/fix script is fine, but how do we attach those attachments from business rule.
 

I have an issue related attachments, we have a table 'core_company' and there are 3 different tables in related list of that table, they are 'vendor risk assessment' , 'IRQ Assessment' , 'vendor engagement'.

when we attach any attachment in any of the table, then it should get attached in to 'core_company' table,

can we do it from business rule or is there any other method for that.

Hoping a reply is given for this query.

 

Thank you.