attachment pdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 03:07 AM
Hi,
I have to move some attachments which is in PDF format, from one instance to another instance. when i tried to move as XML its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 03:37 AM
HI @Avinash Kumar K ,
Hope you are doing great.
Create a custom script to perform the attachment migration. Reference code using ServiceNow's GlideSysAttachment API:
// 1. Query the attachments from the source instance
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', '<source_table_name>');
attachmentGR.addQuery('table_sys_id', '<source_record_sys_id>');
attachmentGR.query();
// 2. Loop through the attachments and copy them to the destination instance
while (attachmentGR.next()) {
var sourceAttachment = new GlideSysAttachment();
sourceAttachment.setTableName('<source_table_name>');
sourceAttachment.setTableSysId('<source_record_sys_id>');
sourceAttachment.setFile(attachmentGR.getValue('file'));
// 3. Create a new attachment record in the destination instance
var destinationAttachment = new GlideSysAttachment();
destinationAttachment.setTableName('<destination_table_name>');
destinationAttachment.setTableSysId('<destination_record_sys_id>');
destinationAttachment.setFileName(attachmentGR.getValue('file_name'));
destinationAttachment.setContentType(attachmentGR.getValue('content_type'));
// 4. Copy the attachment file from the source to the destination
destinationAttachment.write(sourceAttachment.getContentStream());
gs.info('Attachment ' + attachmentGR.getValue('file_name') + ' moved successfully.');
}
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 04:06 AM
Exactly where i have to use this script, please will you assist me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 05:29 AM
@Avinash Kumar K , you can create a on demand scheduled script and use this script there. You can click on execute now to execute the script.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 09:01 AM - edited 06-15-2023 09:01 AM
Hi,
How this script is working without a connection between two instance, will you expalin me please