Skip to main content

Notifications

Business Central forum
Suggested answer

How to set DataItem (Report) that the report choose the current Record?

Posted on by 397 User Group Leader

Hello, I need support to generate a report with the selected record - with the debugger the Rec (SalesHeader) has the right values, but when it creates the report it chooses the first record from the list - so I think the problem is in the report "DataitemTableView" - how is it possible to set a Filter with "No." - maybe to get the result I want?

pastedimage1659616050062v1.png

  • Suggested answer
    T_Mauser Profile Picture
    T_Mauser 397 User Group Leader on at
    RE: How to set DataItem (Report) that the report choose the current Record?

    Hello!

    Maybe I forgot to mention that I'm using the report through sending an Email - so I don't want to show any Requestpage.

    so I called through the OnAction-Trigger following code:

                        RecRef.Open(Database::"Sales Header");
                        Fref := RecRef.Field(3);
                        Fref.SetFilter(Rec."No.");

    and passed it to 

    Report.SaveAs(AttReportUsage, XMLParameters, ReportFormat::Pdf, AttOutStream, RecRef);
    Now everything works as I want ;)
    Thank you for help!
    Tom
  • Suggested answer
    Brad_P Profile Picture
    Brad_P 1,542 on at
    RE: How to set DataItem (Report) that the report choose the current Record?

    Hi,

    You can pass the record to the report. You can call the report by id or instance.

       var

           SalesHeader: Record "Sales Header";

           SalesOrder: Report "Sales Order";

       begin

           SalesHeader.SetRecFilter();

           // Run report by ID -

           Report.Run(Report::"Sales Order", true, false, SalesHeader);

           // Run the report with the report variable

           SalesOrder.SetTableView(SalesHeader);

           SalesOrder.RunModal();

       end;

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: How to set DataItem (Report) that the report choose the current Record?

    Hi,

    Best way is to use a report run function with your current rec as a variable.

    Check out this:

    docs.microsoft.com/.../reportinstance-run-method

    docs.microsoft.com/.../report-run-function

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans