Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

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

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!

Categories:
  • Hot Potato Profile Picture
    Hot Potato 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! 

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 64,563 Super User 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
    Hot Potato 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. :)

  • Hot Potato Profile Picture
    Hot Potato 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

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 64,563 Super User 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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans