web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    92,578 Super User 2025 Season 2 on at
    RE: SavesAS Function & File Management in Business Central On-Prem (ver16)

    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
    RE: SavesAS Function & File Management in Business Central On-Prem (ver16)

    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
    RE: SavesAS Function & File Management in Business Central On-Prem (ver16)

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

  • Suggested answer
    YUN ZHU Profile Picture
    92,578 Super User 2025 Season 2 on at
    RE: SavesAS Function & File Management in Business Central On-Prem (ver16)

    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
    RE: SavesAS Function & File Management in Business Central On-Prem (ver16)

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,160

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,943

#3
Sumit Singh Profile Picture

Sumit Singh 2,823

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans