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;
}
}
}
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.
- 1st row for parent dataitem fields (No., Description),
- 2nd row for child dataitem fields (Code, Description).
领英推荐
Everything is mapped nicely, and the Preview when running the report looks perfect as well:
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.
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