Developer forum

Forum » Integration » Error getting invoice pdf from BC

Error getting invoice pdf from BC

John Cristian Villamar.
Reply

Hi DW.

I am trying to generate a pdf invoice from the DW control panel, it is a custom report, not the standard one. If I generate it from BC it works fine, but when I do it from DW, it returns an "Error - Could not load PDF document", as seen in the attached file.

I checked in the Event viewer of the BC server and I could see that when trying to generate the pdf it generates 3 warnings, always the same, you can see them in the attached pdf file.

How can I check, how DW makes the call to the BC report and where can I change that statement if necessary?

Thanks for the support.


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

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

 

You must be logged in to post in the forum