How do I download multiple attachments from multiple records in a zip file?

Ryan Norton
Giga Contributor

I was wondering if there was any way to download multiple files from multiple records in a single zip file.

1 ACCEPTED SOLUTION

Deepak Ingale1
Mega Sage

Hello,

Please use below link to get an idea of how to setup. It uses JAVA packages and Processor. Use can customize that in processor script based on relationship between the records to find correct attachments to ZIP

https://www.servicenowguru.com/scripting/download-attachments-zip-file/

 

Note: Please mark reply as correct if it answers your question.

View solution in original post

10 REPLIES 10

Jace Benson
Mega Sage

Not that I'm aware of.  You can download all the files for a single record using `download_all_attachments.do?sys_id={SYSID OF TASK}`

I was hoping to get something for multiple records at the same time, and not necessarily on any task tables.

Raj68
Mega Guru

Hi,

Hope below code will help you:

You can use the ZipArchive class to create a ZIP file and stream it to the client. Something like:

$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

and to stream it:

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
https://www.servicenowguru.com/scripting/download-attachments-zip-file/#comment-34336

NOTE: Mark correct or helpful if it helps you.

Warm Regards,

Raj patel

 

Deepak Ingale1
Mega Sage

Hello,

Please use below link to get an idea of how to setup. It uses JAVA packages and Processor. Use can customize that in processor script based on relationship between the records to find correct attachments to ZIP

https://www.servicenowguru.com/scripting/download-attachments-zip-file/

 

Note: Please mark reply as correct if it answers your question.