web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

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

(0) ShareShare
ReportReport
Posted on by 89

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!

I have the same question (0)
  • Verified answer
    matthias_rabus Profile Picture
    160 on at

    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

  • Suggested answer
    YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at

    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

  • matthewjd24 Profile Picture
    89 on at

    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
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    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
    89 on at

    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
    matthias_rabus Profile Picture
    160 on at

    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
    89 on at

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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,050 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,351 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,200 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans