Posted on 02/09/2022 10:47:18
Hi John,
here is the source code of the two methods from our codeunit that are present in your stack trace:
procedure PrintReportasPDF(ReportUsage: Enum "Report Selection Usage"; DocumentNo: Code[30]; ExternalUserId: Text): Text;
var
SalesInvHeader: Record "Sales Invoice Header";
SalesCrMemoHeader: Record "Sales Cr.Memo Header";
SalesHeader: Record "Sales Header";
SalesShipment: Record "Sales Shipment Header";
ReportSelection: Record "Report Selections";
recordReference: RecordRef;
Base64EncodedString: Text;
customer: Record Customer;
begin
Helper.GetCustomer(ExternalUserId, customer);
ReportSelection.RESET;
ReportSelection.SETRANGE(Usage, ReportUsage);
ReportSelection.FINDSET;
case ReportUsage of
ReportSelection.Usage::"S.Invoice":
begin
SalesInvHeader.SETRANGE("No.", DocumentNo);
SalesInvHeader.SETRANGE("Sell-to Customer No.", customer."No.");
SalesInvHeader.FINDSET(false, false);
recordReference.GetTable(SalesInvHeader);
end;
ReportSelection.Usage::"S.Cr.Memo":
begin
SalesCrMemoHeader.SETRANGE("No.", DocumentNo);
SalesCrMemoHeader.SETRANGE("Sell-to Customer No.", customer."No.");
SalesCrMemoHeader.FINDSET(false, false);
recordReference.GetTable(SalesCrMemoHeader);
end;
ReportSelection.Usage::"S.Order":
begin
SalesHeader.SETRANGE(SalesHeader."Document Type", SalesHeader."Document Type"::Order);
SalesHeader.SETRANGE("No.", DocumentNo);
SalesHeader.SETRANGE("Sell-to Customer No.", customer."No.");
recordReference.GetTable(SalesHeader);
end;
ReportSelection.Usage::"S.Shipment":
begin
SalesShipment.SETRANGE("No.", DocumentNo);
SalesShipment.SETRANGE("Sell-to Customer No.", customer."No.");
SalesShipment.FINDSET(false, false);
recordReference.GetTable(SalesShipment);
end;
end;
repeat
ReportSelection.TESTFIELD("Report ID");
Base64EncodedString := Base64EncodedString + GetReportAsPDF(ReportSelection."Report ID", '', recordReference);
until ReportSelection.NEXT = 0;
if StrLen(Base64EncodedString) > 0 then
exit(Base64EncodedString)
else
exit('PrintReportasPDF Failed');
end;
local procedure GetReportAsPDF(ReportId: Integer; ReportParameters: Text; recordReference: RecordRef): Text
var
oStream: OutStream;
tempBlob: codeunit "Temp Blob";
base64Convert: codeunit "Base64 Convert";
iStream: InStream;
begin
tempBlob.CreateOutStream(oStream);
REPORT.SaveAs(ReportId, '', ReportFormat::Pdf, oStream, recordReference);
tempBlob.CreateInStream(iStream);
exit(base64Convert.ToBase64(iStream));
end;
But then the stack goes down deeper into the BC Report.SaveAs function where it fails
So it looks like it misses or has incorrect date time value somewhere
BR, Dmitrij