Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

Make custom report that uses the record you're currently viewing

Posted on by 75

Good afternoon, I'm learning Business Central development for our company so we can customize it for our needs. I'm working on setting up a custom report that you can generate that uses the data on the record you're currently viewing (so if you're looking at a Production Order, the report's dataset is of that record). The only information I've found online doesn't specify how to have the dataset use the record that's currently open. When you run the report, no matter what you have open, it just uses the first record from the table. Obviously that's not very useful.

Below is the code I'm working with right now.

pageextension 50003 MakeCocOnOpen extends "Released Production Order"
{
    trigger OnOpenPage();
    begin
        report.Run(Report::CertificateOfConformance);
    end;
}

report 50003 CertificateOfConformance
{
    DefaultLayout = RDLC;
    RDLCLayout = 'MyRDLReport.rdl';
    
    dataset
    {
        dataitem("Production Order"; "Production Order")
        {
            column(Description; Description){}
            column(No_; "No."){}
            column(Source_No_; "Source No."){}
        }
    }
}

If anyone has any advice for how to do that or could point me to some resources, that would be awesome. Thank you!

  • matthewjd24 Profile Picture
    matthewjd24 75 on at
    RE: Make custom report that uses the record you're currently viewing

    Thank you this makes sense now and it is working. I appreciate the help.

  • Suggested answer
    matthias_rabus Profile Picture
    matthias_rabus 160 on at
    RE: Make custom report that uses the record you're currently viewing

    You don't need to add any additional logic.

    If the first dataitem of your report matches the type of the record you pass in (both belong to the table "Production Order") then BC will use the values of the record in your report.

  • matthewjd24 Profile Picture
    matthewjd24 75 on at
    RE: Make custom report that uses the record you're currently viewing

    I am confused about condition or logic I need to add, I just want the data from the record to be into the Description, No., Source No. columns for the report. Sorry I am very new to this.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,640 on at
    RE: Make custom report that uses the record you're currently viewing

    To access the record you use the trigger OnAfterGetRecord in the dataitem, which will give access the record .

    report 50003 CertificateOfConformance

    {

       DefaultLayout = RDLC;

       RDLCLayout = 'MyRDLReport.rdl';

       dataset

       {

           dataitem("Production Order"; "Production Order")

           {

               column(Description; Description){}

               column(No_; "No."){}

               column(Source_No_; "Source No."){}

               trigger OnAfterGetRecord()

               begin

               --- Add your condition or logic here -----

               end;

           }

       }

    }

  • matthewjd24 Profile Picture
    matthewjd24 75 on at
    RE: Make custom report that uses the record you're currently viewing

    Thank you both for your help. How can I use the passed record in the report? The only thing I can find on this is this article which does not have any mention.

    It's definitely more difficult to self-teach AL than it has been for my past projects like C#. Do you have any advice for good resources to learn? Thank you.

    P.S. Yun Zhu I have visited your Dynamics 365 Lab blog a number of times, it's been really helpful. 

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 69,639 Super User 2024 Season 2 on at
    RE: Make custom report that uses the record you're currently viewing

    Hi, just a example. Print selected sales order.

    pageextension 50135 MyExtension extends "Sales Order List"
    {
        actions
        {
            addafter("Print Confirmation")
            {
                action(NewPrint)
                {
                    Caption = 'New Print';
                    Promoted = true;
                    PromotedCategory = Process;
    
                    trigger OnAction()
                    var
                        SalesHeader: Record "Sales Header";
                    begin
                        SalesHeader.Reset();
                        CurrPage.SetSelectionFilter(SalesHeader);
                        if SalesHeader.FindFirst() then
                            Report.Run(Report::"Standard Sales - Order Conf.", true, true, SalesHeader);
                    end;
                }
            }
        }
    }

    pastedimage1650327919331v1.png

    pastedimage1650327926660v2.png

    Hope this also helps.

    Thanks.
    ZHU

  • Verified answer
    matthias_rabus Profile Picture
    matthias_rabus 160 on at
    RE: Make custom report that uses the record you're currently viewing

    Awesome, you are diving into AL development :-)

    You have to pass the record when calling the report like that:

    Report.Run(Report::CertificateOfConformance, false, false, Rec);

    Rec contains the current Record and is available in pages and page extensions.

    Docs:

    docs.microsoft.com/.../report-run-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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans