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

How to get current record for generating new report in AL?

(0) ShareShare
ReportReport
Posted on by 397 User Group Leader

Hi,

I'm trying to get a current record (Rec.) for generating a Report out of an action button from the page "Misc. Article Information."

Or to get the right Employee Data...

DEBBUGING:

pastedimage1649754313369v2.png

pastedimage1649754408399v5.png

The record "Employee" holds the wrong value for "No." - Why? I am in the right Employee Card, as below:

Should be "DH" not "MH".

pastedimage1649754265114v1.png

Here my code:

report 50101 PA
{
    Caption = 'PA';
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    DefaultLayout = Word;
    WordLayout = 'PA.docx';

    dataset
    {
        dataitem("Employee"; "Employee")
        {

            column(No_; "No.")
            { IncludeCaption = true; }
            column(First_Name; "First Name")
            { IncludeCaption = true; }
            column(Last_Name; "Last Name")
            { IncludeCaption = true; }
            column(Total_Value; "Total Value")
            {
                IncludeCaption = true;
                AutoFormatType = 10;
                AutoFormatExpression = '1,EUR';
            }
        }
        dataitem("TableData"; "Misc. Article Information")
        {

            column(Employee_No_; "Employee No.")
            { IncludeCaption = true; }
            column(Line_No_; "Line No.")
            { IncludeCaption = true; }
            column(Misc__Article_Code; "Misc. Article Code")
            { IncludeCaption = true; }
            column(Description; Description)
            { IncludeCaption = true; }
            column(Serial_No_; "Serial No.")
            { IncludeCaption = true; }
            column(Color; Color)
            { IncludeCaption = true; }
            column(Size; Size)
            { IncludeCaption = true; }
            column(Amount; Amount)
            { IncludeCaption = true; }
            column(From_Date; "From Date")
            { IncludeCaption = true; }
            column(To_Date; "To Date")
            { IncludeCaption = true; }
            column(In_Use; "In Use")
            { IncludeCaption = true; }
            column(Value; Value)
            {
                IncludeCaption = true;
                AutoFormatType = 10;
                AutoFormatExpression = '1,EUR';
            }

            trigger OnPreDataItem()

            begin
                SetFilter("Employee No.", Employee."No.");
                SetFilter("In Use", 'true');
            end;
        }
    }
}

Thank you!

Btw: www.dynamicsuser.net isn't working...

Tom

  • Suggested answer
    Vaishnavi J Profile Picture
    3,058 on at
    RE: How to get current record for generating new report in AL?

    Hi

    You need to change the report logic a bit instead of adding first employee dataitem try to add dataitem misc infomration and then under it add employee. Refer the below code.

    report 50101 PA
    {
        Caption = 'PA';
        UsageCategory = ReportsAndAnalysis;
        ApplicationArea = All;
        DefaultLayout = Word;
        WordLayout = 'PA.docx';

        dataset
        {

            dataitem("TableData"; "Misc. Article Information")
            {

                column(Employee_No_; "Employee No.")
                { IncludeCaption = true; }
                column(Line_No_; "Line No.")
                { IncludeCaption = true; }
                column(Misc__Article_Code; "Misc. Article Code")
                { IncludeCaption = true; }
                column(Description; Description)
                { IncludeCaption = true; }
                column(Serial_No_; "Serial No.")
                { IncludeCaption = true; }
                column(Color; Color)
                { IncludeCaption = true; }
                column(Size; Size)
                { IncludeCaption = true; }
                column(Amount; Amount)
                { IncludeCaption = true; }
                column(From_Date; "From Date")
                { IncludeCaption = true; }
                column(To_Date; "To Date")
                { IncludeCaption = true; }
                column(In_Use; "In Use")
                { IncludeCaption = true; }
                column(Value; Value)
                {
                    IncludeCaption = true;
                    AutoFormatType = 10;
                    AutoFormatExpression = '1,EUR';
                }




                dataitem("Employee"; "Employee")
                {
                    DataItemLink = "No." = field("Employee No.");

                    column(No_;
                    "No.")
                    {
                        IncludeCaption = true;
                    }
                    column(First_Name; "First Name")
                    { IncludeCaption = true; }
                    column(Last_Name; "Last Name")
                    { IncludeCaption = true; }
                    column(Total_Value; "Total Value")
                    {
                        IncludeCaption = true;
                        AutoFormatType = 10;
                        AutoFormatExpression = '1,EUR';
                    }
                }
            }
        }
    }
    And in you action which you have added in Misc. Article information card write the below logic
       action(TestReport)
                {

                    ApplicationArea = All;

                    trigger OnAction()

                    begin

                        if Rec."In Use" then
                            Report.RunModal(50101, true, false, Rec); // Specify the id of your report in 50101

                    end;

                }

    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much

  • T_Mauser Profile Picture
    397 User Group Leader on at
    RE: How to get current record for generating new report in AL?

    Your first solutions doesn't work, so far - result is that I get every item on the report - not only the "In Use" = true.

    Trying another solutions...

    I want to display data from the employee, like first and last name, on the report - for verification that it's the right one.

    So the case is to get the right data to my xml fields - because now it is printing the first employee from the list - when adding normal dataitems to my report - like in the code above.

  • Suggested answer
    Vaishnavi J Profile Picture
    3,058 on at
    RE: How to get current record for generating new report in AL?

    Hi,

    Can you explain on what you require in the data and what your expectations are?

    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much

  • T_Mauser Profile Picture
    397 User Group Leader on at
    RE: How to get current record for generating new report in AL?

    Nice - thank you!

    I was already working on something like that ^^

    Do you know, is it possible to hand over more than one table?

    Need data from a Employee record...

  • Suggested answer
    Vaishnavi J Profile Picture
    3,058 on at
    RE: How to get current record for generating new report in AL?

    Hi,

    In your Misc Article  Information page add the below logic in your action.

    action(TestReport)

               {

                   ApplicationArea = All;

                   trigger OnAction()

                   begin

                       if Rec."In Use" then

                           Report.RunModal(50121, false, false, Rec); // Specify the id of your report in 50121

                   end;

               }

    Remove the filters added in the predataitem.

    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,269 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans