Migrating attachments between instancesIssue This article describes how to migrate attachments from one ServiceNow instance to another by exporting records from the sys_attachment table as XML and importing them into the target instance. An admin role is required on both instances. Release All releases Resolution Complete all steps on the source instance first, then repeat the import steps on the target instance. An admin account is required on both instances. 1. Log in to the source instance as an admin user. 2. Navigate to the sys_attachment table. Filter the list using the condition `table name is <target_table>`, where `<target_table>` is the name of the table whose attachments are being migrated (for example, `incident`). Export the filtered results to an XML file. 3. Navigate to System Definition > Script - Background. 4. Copy the following script into the script input field. //***********The number of recordsPerUrl can be changed. This determines the total number of records that will be queries.Note: The system will break somewhere between 200-250 records.The more records you try to export, the longer it will take and may cause the export to break. */ var recordsPerUrl = 200; //Static variables, do not changevar countTotal = 1;var count = 1;var totalRecords = 0;var urls = new Array();var attach = new GlideRecord('sys_attachment');var instance = gs.getProperty('glide.servlet.uri');var startUrl = instance+"sys_attachment_doc_list.do?sysparm_query=sys_attachmentIN"var url = startUrl; attach.addQuery('table_name', 'CONTAINS', 'ZZ_YY');attach.query(); totalRecords = attach.getRowCount() gs.print("Total of "+totalRecords+ " image attachments"); //Create urlswhile (attach.next()) { url += attach.sys_id + "%2C"; count++ countTotal++; if ((count == recordsPerUrl) || (countTotal == totalRecords)) { urls.push(url); count = 1; url = startUrl }} //Write out urlsfor (var i = 0; i < urls.length; i++)gs.print(urls[i]); //****END******* 5. In the script, locate the following line: ``` attach.addQuery('table_name', 'CONTAINS', 'ZZ_YY'); ``` 6. Replace `ZZ_YY` with the name of the table whose attachments are being migrated. For example, for the `incident` table the line becomes: ``` attach.addQuery('table_name', 'CONTAINS', 'incident'); ``` 7. Run the script. The output on the right side of the screen displays URL of sys_attachment_doc records. 8. Navigate to the URL in the output to open sys_attachment_doc records. 9. Export the sys_attachment_doc records to an XML file. 10. Log in to the target instance as admin user. 11. Import the XML files exported from the source instance. Related Links