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

Copy list page filter to request page of report

(0) ShareShare
ReportReport
Posted on by 555

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.

I have the same question (0)
  • Rbansode Profile Picture
    5 on at

    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

  • Morten Steengaard Profile Picture
    555 on at

    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.

  • Verified answer
    Morten Steengaard Profile Picture
    555 on at

    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;

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,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans