Nested repeater dataitem in Word Layout (D365 Business Central)

TLDR: If you need to display a child dataitem with repeater inside a parent dataitem with repeater, no extra tricks are required: you don't need extra cells, columns or rows, you just insert the child dataitem repeater control inside the parent dataitem repeater control. https://github.com/userutf8/WordLayoutNestedDataitems

Let's create a simple table "Item Feature" with Code (PK), "Item No." (FK) and Description fields. Each Item has zero or many Item Features. Let's add some data.

table 55200 "Item Feature"
{
    DataClassification = CustomerContent;

    fields
    {
        field(1; Code; Code[20])
        {
        }
        field(2; "Item No."; Code[20])
        {
            TableRelation = Item;
        }
        field(3; Description; Text[128])
        {
        }
    }

    keys
    {
        key(PK; Code)
        {
            Clustered = true;
        }
    }
}        


Item Feature table data

We want a report that prints Items which have Item Features, and for each of those Items prints all Item Features.

report 55200 "Item Features"
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    DefaultLayout = Word;
    WordLayout = 'ItemFeatures_v1.docx';

    dataset
    {
        dataitem(Item; Item)
        {
            column(ItemNo; "No.")
            {
                IncludeCaption = true;
            }
            column(ItemDescription; Description)
            {
                IncludeCaption = true;
            }

            dataitem(ItemFeature; "Item Feature")
            {
                DataItemLink = "Item No." = field("No.");
                column(FeatureCode; Code)
                {
                    IncludeCaption = true;
                }
                column(FeatureDesription; Description)
                {
                    IncludeCaption = true;
                }
            }

            trigger OnAfterGetRecord()
            var
                ItemFeature: Record "Item Feature";
            begin
                ItemFeature.SetRange("Item No.", "No.");
                if ItemFeature.IsEmpty() then
                    CurrReport.Skip();
            end;
        }
    }
}        

Let's make a simple layout now.

  • We build our project and open our ItemFeatures_v1.docx Layout file.
  • We insert a table 2x2:

- 1st row for parent dataitem fields (No., Description),

- 2nd row for child dataitem fields (Code, Description).

  • Then we Insert Content Control/Plain Text for each of those.
  • Then we select both rows and Insert Content Control/Repeater for the parent dataitem.
  • Then we select 2nd row only and Insert Content Control/Repeater for the child dataitem.
  • Then we save the layout and rebuild our project. If we open layout again we see the following:


Word Layout developer mode.

Everything is mapped nicely, and the Preview when running the report looks perfect as well:


Item Features report preview

Note: if there are problems with layout, please make sure to check your dataitem and column names: low dash symbol '_' in the end of a column name may break the layout without any warnings. For example, we have dataitem Item, and when we create a column for "No." then VS Code suggeste to go with a column name No_. If you decide to go with that column name, your report won't display properly.


low dash in column name symbol suggested by VS Code

It's also important to use Developer mode in Design mode and to make sure that mappings are correct after rebuild of the project.

And that's it for now, thank you for reading.

#BusinessCentral, #Report, #Word


要查看或添加评论,请登录

Roman Ivanov的更多文章

社区洞察

其他会员也浏览了