web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    260 on at
    RE: In Report, Can it be dataitem DataItemLink dynamically defined according to a field in the upper dataitem or variable?

    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
    95,305 Super User 2025 Season 2 on at
    RE: In Report, Can it be dataitem DataItemLink dynamically defined according to a field in the upper dataitem or variable?

    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
    RE: In Report, Can it be dataitem DataItemLink dynamically defined according to a field in the upper dataitem or variable?

    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

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 3,421

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,878 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,645 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans