web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Bundle reports into a zip file

(0) ShareShare
ReportReport
Posted on by 75

Hi there!

I am working on an extension for our client. And here is what we try to achieve:  Loop the shipment lines to get the source no, run a report for each source no, and save all the reports in a zip file. 

I came up with the following code. It can download an empty zip file that doesn't have any report in it. I am wondering which part was wrong. Please advise,

Thanks a lot!

local procedure BundleReports(ShipmentHeader: Record "Warehouse Shipment Header")
var
ReportParameter: Text;
ShipmentLines: Record "Warehouse Shipment Line";
FileManagement: Codeunit "File Management";
DataCompression: Codeunit "Data Compression";
FileName: Text;
BaseName: Text;
ZipFileName: Text;
GetTotalNumberOfFiles: Integer;
ZipOutStream: OutStream;
ZipInStream: InStream;
blobStorage: Codeunit "Temp Blob";


begin

DataCompression.CreateZipArchive();

blobStorage.CreateOutStream(ZipOutStream);


ZipFileName := ShipmentHeader."No." + '.zip';

ShipmentLines.Reset();
ShipmentLines.SetRange("No.", ShipmentHeader."No.");
ShipmentLines.SetCurrentKey("Source No.");
if ShipmentLines.FindSet() then begin
repeat

FileName := ShipmentLines."Source No.";
Report.SaveAs(50106, ShipmentLines."Source No.", ReportFormat::Pdf, ZipOutStream);

until ShipmentLines.Next() = 0;
end;
DataCompression.SaveZipArchive(ZipOutStream);
DataCompression.CloseZipArchive();
blobStorage.CreateInStream(ZipInStream);
DownloadFromStream(ZipInStream, '', '', '', ZipFileName);
end;

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    Working solution can be seen here: https://youtu.be/I44oxIoEspM

    Link on the video to Erik’s GitHub so you can download his code and adapt accordingly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans