Need to download attachments from attachment table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2023 03:40 PM
I need to download attachments from the attachment table [sys_attachment] with a filter. There was an old way using processors but they are no longer available. I searched that rest api is another option but you can only get json file with download link but that won't do anything. I need the actual files. Has anyone found a simple way to get this done?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 08:32 AM - edited ‎04-16-2023 08:34 AM
Hi,
https://[instance_name].service-now.com/sys_attachment_list.do?sysparm_query=&sysparm_view=
filter based on the available fields and then click on the desired record. change the file extension if needed to match the content type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 10:37 AM
Hi @Chang Yeon Hong ,
I trust you are doing fine.
You can use below code for as a solution
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addEncodedQuery('YOUR_FILTER_HERE');
attachmentGr.query();
if (attachmentGr.next()) {
var file = new GlideSysAttachment().getAttachmentStream(attachmentGr);
// Do something with the file
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 11:52 AM - edited ‎04-16-2023 01:11 PM
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addEncodedQuery('table_nameSTARTSWITHsn_app');
attachmentGr.query();
while (attachmentGr.next()) {
gs.info("Attachment file name: " + attachmentGr.file_name);
var file = new GlideSysAttachment().getAttachmentStream(attachmentGr);
gs.info("File: " + file);
// Do something with the file
}
Results in:
*** Script: Attachment file name: response.txt
*** Script: File: undefined
*** Script: Attachment file name: response.txt
*** Script: File: undefined
*** Script: Attachment file name: response.txt
*** Script: File: undefined
I did find documentation, See below. But I fail to see how that is useful to download files. The files can be downloaded from the list view of sys_attachment as I posted above.
However. 'getAttacmentStream()' is not documented.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 05:52 PM
I need to find a way to download multiple files at one go. Like a filter the sys_attachment table and download the files into zip.