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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

In Report, Can it be dataitem DataItemLink dynamically defined according to a field in the upper dataitem or variable?

(0) ShareShare
ReportReport
Posted on by 15

Hello.

I'm trying to make a report, packing list.

It has a filter "No.".

If the value of "Multi Document Package" of the record with the "No." is true,

then should list the combined orders in the same package, else list the record itself.

For the case in the below,

if filter "No." is P000130, then "Multi Document Package" value is true, so the report prints out "P000130-SO-0000508" and "P000130-SO-0000509", and their details.

If filter "No." is P000208, then "Multi Document Package" value is false, so the report print out "P000208" and its details.

pastedimage1654343290313v1.png

I expected I can dynamically filter it in report page, but it looks not that simple.

Here is my code I expected it will work. But as you know, if statement is not allowed in dataitem.

if Multi_Document_Package then
        DataItemLink = "Original Package No." = FIELD("No.");
else
       DataItemLink = "No." = FIELD("No.");

Can someone give me an advise?

Thank you.

report 70705 "TRU Pckg No Packing Lst V2-T"
{
    DefaultLayout = RDLC;
    RDLCLayout = './RDLC/LAX SalesOrderPackingList_70704_TruTest_v0.62.rdlc';
    ApplicationArea = All;
    Caption = 'Pacakge Sales Orders Packing List V2 (TruTest)';
    UsageCategory = ReportsAndAnalysis;

    dataset
    {
        dataitem(PackageFilter; "LAX Package")
        {
            RequestFilterFields = "No.";
            DataItemTableView = SORTING("Source Type", "Source Subtype", "Source ID") WHERE("Source Type" = CONST(36));

            column(No_; "No.")
            {
            }
            column(Source_ID_; "Source ID")
            {
            }
            column(Multi_Document_No_; "Multi Document No.")
            {
            }

            column(Multi_Document_Package;"Multi Document Package")
            {
            }

            column(varIsMultiDocument;IsMultiDocument)
            {
            }            

            dataitem(Package; "LAX Package")
            {
                if Multi_Document_Package then
                    DataItemLink = "Original Package No." = FIELD("No.");
                else
                    DataItemLink = "No." = FIELD("No.");

                //if Multi_Document_Package then                
                //    DataItemTableView = SORTING("Source Type", "Source Subtype", "Source ID") WHERE("Source Type" = CONST(36), "Original Package No." = CONST(FIELD("No.")));
                //else
                //    DataItemTableView = SORTING("Source Type", "Source Subtype", "Source ID") WHERE("Source Type" = CONST(36), "Original Pa" = FILTER(FIELD("Multi Document No.")));
                
                PrintOnlyIfDetail = true;

                column(Package__Source_ID_; "Source ID")
                {
                }
                column(Package__No__; "No.")
                {
                }
                column(Package__Packing_Date_Caption; FieldCaption("Packing Date"))
                {
                }
                column(Package__Source_ID_Caption; FieldCaption("Source ID"))
                {
                }
                column(Package_Source_Subtype; "Source Subtype")
                {
                }

                dataitem("Package Line"; "LAX Package Line")
                {
                    DataItemLink = "Package No." = FIELD("No.");
                    DataItemTableView = SORTING("Package No.", "Line No.") WHERE("Quantity (Base)" = FILTER(> 0));
                    column(Package_Line_Type; Type)
                    {
                    }
                    column(Package_Line__No__; "No.")
                    {
                    }
                    column(Package_Line_Description; Description)
                    {
                    }
                    column(Package_Line_Quantity; Quantity)
                    {
                    }
                    column(Package_Line_Package_No_; "Package No.")
                    {
                    }
                    column(Package_Line_Line_No_; "Line No.")
                    {
                    }
                }

                trigger OnAfterGetRecord()
                begin
                    EShipFormatAddr.PackageShipTo(ShipToAddress, Package);                    
                end;
            }


            trigger OnAfterGetRecord()
            begin
                Package2.Reset;
                Package2.SetCurrentKey("No.");
                Package2.SetRange("No.", "No.");
                IsMultiDocument := Package2."Multi Document Package";
                strMultiDocumentNos := Package2."Multi Document No.";
            end;
        }
    }

    requestpage
    {

        layout
        {
        }

        actions
        {
        }
    }

    labels
    {
    }

    var
        Package2: Record "LAX Package";
        ShipToAddress: array[8] of Text[100];
        PackageCount: Integer;
        Sales_Order_Packing_ListCaptionLbl: Label 'Sales Order Packing List';
        CurrReport_PAGENOCaptionLbl: Label 'Page';
        PackageCountCaptionLbl: Label 'Total Packages';
        ShipToAddress_1_CaptionLbl: Label 'Ship-to';
        UOMCaptionLbl: Label 'UOM';
        Package_No_CaptionLbl: Label 'Package No.';
        Closed_by_Packing_StationCaptionLbl: Label 'Closed by Packing Station';
        EShipFormatAddr: Codeunit "LAX EShip Format Address";

        IsMultiDocument: Boolean;
        strMultiDocumentNos: Text;

}

I have the same question (0)
  • Damiano Zaniboni Profile Picture
    262 on at

    Hi mate! You can use a temporary table to print report what you want. On trigger OnPreDataItem, you can load a temporary table in different way if the multi_document_package var is true or false. Then you can use as dataitem the temporary table just load and then print it. Unfortunately there are some properties you can't valued dinamically. DataItemLink is one of these. 

    I hope I give you an idea for your report.

    DZ

  • Suggested answer
    YUN ZHU Profile Picture
    98,231 Super User 2026 Season 1 on at

    Hi, I agree with Damiano, unlike TableRelation Property, DataItemLink Property (Reports) does not support Conditions (If).

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-dataitemlink-reports-property

    So in this case, you can create a new table and insert data when the Report is opened (such as OnPreReport (Report) Trigger), you can get different data according to the conditions in your code.

    Then the report only needs to display the data. This will make the design of the report simpler.

    Hope this helps as well.

    Thanks.

    ZHU

  • antiqua Profile Picture
    15 on at

    Thank you guys. I will try your idea. That means I have to make a modification or a new RDLC, also. :_(

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,960 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,084 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,047 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans