
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;
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