The report designed in the Walkthrough: Designing a
Simple Report was very simple: it was based on one table
which it ran through and printed the records. In this walkthrough,
you will learn how to design reports that are based on more than
one table.
The sample report that you will create uses two tables: the
Customer table and the Sales Line table, which contains
not-yet-posted sales orders that contain information about the
actual items that have been ordered by the customers. There is a
one-to-many relationship between the two tables—while one customer
can have many items on order, each sales line can only refer to one
customer.
Prerequisites
-
To complete this walkthrough, you will need:
-
Microsoft Dynamics NAV installed with a developer license.
-
The CRONUS International Ltd. demo data company installed.
Defining the Data Model
In this section you will define the data model. The report must
run through the Customer data item, and for each record in the
Customer data item, select records in the Sales Line data item if
the Sell-to Customer No. field has the same value as the No. field
in the Customer data item. If there are no Sales Line records for a
Customer, nothing is printed—not even the information from the
Customer data item.
To define the data model
-
From Microsoft Dynamics NAV, click Tools, and then click
Object Designer.
-
In Object Designer, click the Report button, click
New, and then select Create a blank report.
-
In the Report Designer window, select the Customer
table as the first data item, and the Sales Line table as
the second data item.
-
Select the Sales Line data item and click the right-arrow
button once to indent it.
-
Open the Properties window (SHIFT+F4) for the Sales
Line data item.
-
Set the DataItemLinkReference property to
Customer. In most cases, including this one, this is the
default.
-
In the Value field of the DataItemLink property,
click the AssistButton to open the DataItem Link
window.
-
In the Field field, enter the name of the field from
Sales Line table that must correspond to a field from the
Customer table. Use the lookup function to select the field.
For this example, select the Sell-to Customer No. field.
-
In the Reference Field field, enter the name of the field
from the Customer table that must correspond to the field
from the Sales Line table. Again, use the lookup function to
select the field. In this example, select the No. field from
the Customer table.
-
Finally, open the Properties window for the
Customer data item, and set the PrintOnlyIfDetail
property to Yes. This means that the Customer body sections
are only printed if there is data to print from the Sales Line
table.
Designing the Sections
Because you already know how to design the sections for a report
with one data item, the following procedure shows how to design
sections that involve two data items.
To design the sections
-
Open Section Designer, click Edit, click Insert
new, and then add a Header section for the Customer data
item.
-
Click View, and then click Field Menu to open the
Field Menu window.
-
Add the No., Name, Address, and Phone
No. fields to the Customer, Body (2) section.
Move the labels up into the Header section.
-
Open the Field Menu window and add the Document
No., Shipment Date, Description, Quantity,
Unit Price, and Amount fields to the Sales
Line, Body (1) section.
-
Move the labels into the header section of the Customer data
item.
-
Set the PrintOnEveryPage property of the Customer,
Header (1) section to Yes. Now the labels for both
the Customer records and the Sales Line records will be printed as
column captions in the Customer, Header (1)
section.
-
Change the labels for the Sales Line columns to normal
font weight instead of the default bold to make the connection
between labels and data clear.
-
Change the text boxes of the Customer data item to bold,
to make these records stand out among the lines that are
printed.
-
Resize the Sales Line labels to occupy only one line, and
add an empty line to the header section.
-
Save and close the report, and run it from Object Designer.
See Also