Hello fellow developer,
I am trying to download a Sales Confirmation report automatically when Sales Header being released without using RunRequestPage().
Instead, I am using RecordRef. Below is my code but whenever the report is generated, it is still generating for all Sales Header records and not seem to be picking up my SalesHeader filter:
codeunit 50205 MyCodeunit
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Sales Document", 'OnAfterPerformManualCheckAndRelease', '', false, false)]
local procedure AutoPrintReport(SalesHeader: Record "Sales Header")
var
ReportToPrint: 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
Clear(ReportOutstream);
Clear(ReportToPrint);
TempBlob.CreateOutStream(ReportOutstream);
SORecordReference.GetTable(SalesHeader);
LayoutSelection.SetTempLayoutSelected('1305-000001');
ReportToPrint.SaveAs('', ReportFormat::Pdf, ReportOutstream, SORecordReference);
FileManagement.BLOBExport(TempBlob, Format(ReportToPrint) + '_' + Format(CURRENTDATETIME, 0, '<Day,2><Month,2><Year4><Hours24><Minutes,2><Seconds,2>') + '.pdf', true);
end;
}
Can someone please help me to point out if I used the RecordRef.GetTable() or Report.SaveAs() incorrectly? Or there is no way of printing report for specific record without using the Report Parameters.