web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

SavesAS Function & File Management in Business Central On-Prem (ver16)

(0) ShareShare
ReportReport
Posted on by 25

I am currently working on a Packing List report that needs to save as pdf automatically in a particular path in our server upon click of an action button in a Sales Order. I am new to development, I have tried following the saveaspdf method in the Microsoft website however when the action button was ticked now, an I/O Error shows even when I already deleted the codes I have done in the Visual Studio Code. Is there any sample code you can advise to achieve the first scenario I have mentioned above? Another twist to this is that, it should only save when the sell-to customer code is equal to Customer 1, Customer 2 & Customer 3...help me please! Will File Management Code Unit help me with this? Thank you in advance!

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    98,026 Super User 2026 Season 1 on at

    Hi, I have some simple examples that I hope will help you.

    https://yzhums.com/7200/

    https://yzhums.com/21202/

    https://yzhums.com/20030/

    Thanks.

    ZHU

  • Hot Potato Profile Picture
    25 on at

    HI, thank you for the link, however we don't need it to run a request page. It should saves automatically upon click of an action in our Sales Header Page. I have tried creating the code however when I run it an error "An I/O exception occurred during the operation" pops up when I click the Action Button "Create WMS Shipment" in the Sales Header. Below is the sample code that I have created, can you please tell me where I gone wrong?

    I would really appreciate your help on this. . Thank you. 

    pastedimage1658303679739v1.png

  • Hot Potato Profile Picture
    25 on at

    Hi, I am totally new to this, I have replied on your response below...Thank you. :)

  • Suggested answer
    YUN ZHU Profile Picture
    98,026 Super User 2026 Season 1 on at

    Hi, The Report.SaveAsPdf method should be fine in the On-Pre version. It's a little weird.

    Well, can the solution below give you some hints? Just using Report.SaveAs(Integer, Text, ReportFormat, var OutStream [, RecordRef) Method.

    https://yzhums.com/wp-content/uploads/2022/01/CustomFilenameForReportExport.mp4

    pageextension 50100 ZYSalesOrderExt extends "Sales Order List"
    {
        actions
        {
            addafter("Print Confirmation")
            {
                action(SaveConfirmationAsPdf)
                {
                    Caption = 'Save Confirmation As Pdf';
                    ApplicationArea = All;
                    Image = Export;
                    Promoted = true;
                    PromotedCategory = Category8;
                    PromotedIsBig = true;
                    trigger OnAction()
                    var
                        TempBlob: Codeunit "Temp Blob";
                        FileManagement: Codeunit "File Management";
                        OStream: OutStream;
                        SalesHeader: Record "Sales Header";
                        RecRef: RecordRef;
                    begin
                        SalesHeader.Reset();
                        Clear(OStream);
                        CurrPage.SetSelectionFilter(SalesHeader);
                        RecRef.GetTable(SalesHeader);
                        TempBlob.CreateOutStream(OStream);
                        Report.SaveAs(Report::"Standard Sales - Order Conf.", '', ReportFormat::Pdf, OStream, RecRef);
                        FileManagement.BLOBExport(TempBlob, 'Sales Order_'   UserId   '_'   Format(CurrentDateTime, 0, '')   '.pdf', true);
                    end;
                }
            }
        }
    }

    Hope this helps.

    Thanks.

    ZHU

  • Hot Potato Profile Picture
    25 on at

    Thank you for helping me with this, I was able to achieve what you have shown on your video and it is really a great help for me. However, they instead of saving it in my C:Drive, they want that saved in a a certain location in our Server, like \\RAKFILESERVER\WAREHOUSE\PACKING LIST. Is there any way for this? Thank you soooo much! 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,091 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,032 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 946 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans