Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Copy list page filter to request page of report

(0) ShareShare
ReportReport
Posted on by 543

Hi experts,

I have made my own report in my extension on Business Central cloud.

I have a button that is used to call the report and save it as a pdf-file. To do that, I call the request page first and then run the report.

If the user has a filter on the list page, it must be copied to the request page on the report. And if the user has not a filter on field X, it must be added with the value from field X in the current line.

I do this:

MyLine.CopyFilters(Rec);

if MyLine.GetFilter("X") = '' then begin
MyLine.SetFilter("X", '%1', Rec."X");
end;

XmlParameters := Report.RunRequestPage(50102);

if XmlParameters <> '' then begin
TempBlob.CreateOutStream(OStream, TextEncoding::UTF8);
Report.SaveAs(50102, XmlParameters, ReportFormat::Pdf, OStream);
...

How do I copy the current filter from the list page to the request page?

(The special thing about this report is that it prints several lines from the list page, the user is in.)

Hope you can help.

  • Verified answer
    Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: Copy list page filter to request page of report

    This is the solution:

    I had to use a Report object and call the method SetTableView. This works fine:

    var

       myReport: Report "Some Report";

       OStream: OutStream;

       TempBlob: Codeunit "Temp Blob";

       cnv64: Codeunit "Base64 Convert";

       email: Codeunit Email;

       emailMsg: Codeunit "Email Message";

       XmlParameters: Text;

       IStream: InStream;

       txtB64: Text;

    Clear(myReport);

    myReport.SetTableView(myRecord);

    XmlParameters := myReport.RunRequestPage();

    if XmlParameters <> '' then begin

       TempBlob.CreateOutStream(OStream);

       Clear(myReport);

       myReport.SaveAs(XmlParameters, ReportFormat::Pdf, OStream);

       TempBlob.CreateInStream(IStream);

       txtB64 := cnv64.ToBase64(IStream, true);

       if txtB64 = '' then begin

           Error('Empty report...');

       end;

       emailMsg.Create(Vendor."E-Mail", 'List', '');

       emailMsg.AddAttachment('myList.pdf', 'application/pdf', txtB64);

       email.OpenInEditor(emailMsg);

    end;

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: Copy list page filter to request page of report

    Hi Rahul,

    Thank you for your reply.

    I have to use "Report.SaveAs(50102, XmlParameters, ReportFormat::Pdf, OStream);" because I am in cloud and don't want to save the pdf file. I want to send it attached to an e-mail.

    Report.SaveAs() does not show the request page, so I call "Report.RunRequestPage(50102);" first.

    If I add "CurrPage.SetSelectionFilter(Record)" before the call to RunRequestPage, it does not change anything. The current filter on the list page still cannot be seen on the request page. (It works fine when I on another button just want to preview/print the report and only use "Report.RunModal(...)".)

    Besides, Report.SaveAsPdf() cannot be used in cloud. It is only for on-premise.

  • Rbansode Profile Picture
    Rbansode 5 on at
    RE: Copy list page filter to request page of report

    I think you can use the CurrPage.SetSelectionFilter(Record) to get the selected records from the page. Then use the "Report.SaveAsPdf" function and pass the Record as a parameter.

    Look at following resources for more information.

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

    docs.microsoft.com/.../page-setselectionfilter-method

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,431 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans