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

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

I have the same question (0)
  • Suggested answer
    Vaishnavi J Profile Picture
    3,062 on at

    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

  • T_Mauser Profile Picture
    397 User Group Leader on at

    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,062 on at

    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

    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,062 on at

    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

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

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,007 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 948 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans