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...
Answered

Report.SaveAsPdf saves first report from the Sales Orders

(0) ShareShare
ReportReport
Posted on by 12

Hello dear community!

Having a problem using SaveAsPdf function, don't know what's missing.

So I added trigger OnAfterAction in Post Action in Sales Order.

            trigger OnAfterAction()
            var
                PdfFilePath: Text;
                PdfFileName: Text;

            begin
                PdfFileName := Rec."No." + '_' + Format(Rec."Posting Date") + '_' + Rec."Sell-to Customer Name";
                PdfFilePath := 'C:\DL\' + PdfFileName + '.pdf';
               
                Report.SaveAsPdf(ReportID, PdfFilePath);
            end;

PdfFileName is being generated correctly, it gets the right No., Posting Date and Sell-to Customer Name from the order, but Report.SaveAsPdf function saves report from the first Sales Order in the list.
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,788 Moderator on at

    Hi,

    You can try this way

            var
            DocRef: RecordRef;
            FldRef: FieldRef;
            Cust: Record Customer;
            
                    DocRef.GetTable(Cust);  
                    FldRef := DocRef.Field(Cust.FieldNo("No."));
                    FldRef.SetRange(Cust."No.");
                    if DocRef.FindFirst() then
                    begin   
                        CustomerBalancetoDate.InitializeRequest(false, false, false, YourDate);
                        CustomerBalancetoDate.SetTableView(Cust);
                        CustomerBalancetoDate.SaveAs('', ReportFormat::Pdf, Outstrebody, DocRef);
                    end;

  • Verified answer
    YUN ZHU Profile Picture
    98,231 Super User 2026 Season 1 on at

    Hi, It looks like you are using the On-Pre version. Please try the code below.

    pastedimage1683594415803v1.png

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/report/report-saveaspdf-method

    pastedimage1683594432949v2.png

    Hope this helps.

    Thanks

    ZHU

  • SINTEGRA Profile Picture
    12 on at

    Thank you Yun Zhu :) Didn't get right that Optional parameter, now I understand it. My question solved.

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 1,960 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,084 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,047 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans