Download multiple attachments from multiple records in a zip file?

Abhishek142
Tera Contributor

Hi All,

 

I have a requirement to download an attachment from multiple records in zip file. I have seen the ServiceNow guru solution but that solution is no more working in New York. As the processor is depreciated hence we cant use that solution anymore.

 

Kindly advise if anyone has done the same.

 

Thanks

7 REPLIES 7

Tanushree Doiph
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,

Tanushree

Hi Tanushree-

 

I have seen this post earlier but I dint get how to implement the same? As mentioned in my post also, i have seen servicenow guru solution but that solution is not working in New York version and I suspect this will also not work.

 

Did you try the same in New York?

 

Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Abhishek,

Do you want all attachments on a record to be downloaded?

if yes then check below link and it may help you:

https://community.servicenow.com/community?id=community_question&sys_id=aad66f74db28cc182be0a851ca96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur- Would this download all attachments as zip file?