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

Notifications

Announcements

No record found.

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,708 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
    95,697 Super User 2025 Season 2 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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,606

#2
YUN ZHU Profile Picture

YUN ZHU 931 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans