Hi fellow developers!
I am working on a project to auto download Sales Order report upon Sales Order Releases.
While the code works perfectly when ONE order is released, when we tried to mass release multiple Sales Orders by using the 'Select More' and 'Release' on the Sales Order List, only the last selected Sales Order report is downloaded.
I've tried running my codeunit in debug mode and confirmed the codeunit actually ran multiple times as expected. Every time the codeunit is ran with the right Sales Order Record till the last line but there was nothing downloaded until the last selected Sales Order Record is ran and a report is downloaded for last sales order only.
Below is my code:
codeunit 50205 "Download Report SO Release"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Sales Document", 'OnAfterPerformManualCheckAndRelease', '', false, false)]
local procedure DownloadReport(SalesHeader: Record "Sales Header")
var
SOReport: Report "Sales Order";
TempBlob: Codeunit "Temp Blob";
LayoutSelection: Record "Report Layout Selection";
ReportOutstream: OutStream;
ReportParameter: text;
FileManagement: Codeunit "File Management";
SORecordReference: RecordRef;
SalesHeaderFilter: Record "Sales Header";
begin
if SalesHeader."Sell-to Customer No." = 'Customer that requires report printing' then begin
Clear(ReportParameter);
Clear(ReportOutstream);
Clear(SOReport);
TempBlob.CreateOutStream(ReportOutstream);
SalesHeaderFilter.SetFilter("No.", '=%1', SalesHeader."No.");
SalesHeaderFilter.FindFirst();
SORecordReference.GetTable(SalesHeaderFilter);
LayoutSelection.SetTempLayoutSelected('10075-000001');
Report.SaveAs(Report::"Sales Order", '', ReportFormat::Pdf, ReportOutstream, SORecordReference);
FileManagement.BLOBExport(TempBlob, Format('SOReport') + '_' + Format(SalesHeader."External Document No.") + '_' + Format(CURRENTDATETIME, 0, '<Year4><Month,2><Day,2><Hours24><Minutes,2><Seconds,2>') + '.pdf', true);
end;
end;
}
Has anyone tried downloading multiple files using AL before that can help with the above? Thanks a lot in advance!
Thank you,
Ginger