Skip to main content

Notifications

Announcements

No record found.

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.
  • SINTEGRA Profile Picture
    SINTEGRA 12 on at
    RE: Report.SaveAsPdf saves first report from the Sales Orders

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

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 74,115 Super User 2024 Season 2 on at
    RE: Report.SaveAsPdf saves first report from the Sales Orders

    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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Report.SaveAsPdf saves first report from the Sales Orders

    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;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans