Business Central Cloud renaming a PDF report using FileManagement.BLOBExport

Business Central Cloud renaming a PDF report using FileManagement.BLOBExport

On the Business Central Cloud, to save a report in PDF format and change its name while saving, you can use a STREAM BLOB through the “Temp blob” codeunit.

Once this is done, use the function then the BLOBExport function present in the “File Management” codeunit to export the report created with the “REPORT.SAVEAS” command, changing its name during saving.

Example:

Code

pageextension 50001 SalesInvoiceext extends "Sales Invoice"
{
    layout
    {        

    }

    actions
    {
        addafter("Test Report")
        {
            
            action("Download PDF Report")
            {
                ApplicationArea = All;
                Image = ExportFile;
                trigger OnAction()
                var

                    TempBlob_lRec: Codeunit "Temp Blob";
                    Out: OutStream;
                    RecRef: RecordRef;
                    FileManagement_lCdu: Codeunit "File Management";
                    SalesHeader_lRec: Record "Sales Header";
                begin
TempBlob_lRec.CreateOutStream(Out, TEXTENCODING::UTF8);  // Create Outstream
                    // Record filter
                    SalesHeader_lRec.Reset;  
         SalesHeader_lRec.Setrange(“Document Type”,  “Document Type”::Order);                
                    SalesHeader_lRec.SetRange("No.", Rec."No.");
                    SalesHeader_lRec.FindFirst();
                    RecRef.GetTable(SalesHeader_lRec);
                    
	         // REPORT “SAVEAS” and BLOBExport
                    REPORT.SAVEAS(5001, '', REPORTFORMAT::Pdf, Out, RecRef);    // save report in TempBlob di recRef
                    FileManagement_lCdu.BLOBExport(TempBlob_lRec, STRSUBSTNO('Proforma_%1.Pdf', "No."), TRUE);   // export report in PDF format
                end;

            }

        }

    } 

}

Link

https://github.com/rstefanetti/AL-Code-Samples-Education/tree/AL-FileManagementBLOBExport_Demo

L'articolo Business Central Cloud renaming a PDF report using FileManagement.BLOBExport proviene da Roberto Stefanetti Blog - Microsoft Dynamics 365 Business Central.

Comment List
Related
Recommended