Reports, like forms, can be
customized to include and exclude information, and you can modify their
design and layout. As with forms, the design and layout of a report
depend on settings on the table and on the report itself. The best
practice is, once again, to keep as much of the business logic as
possible with the table methods or metadata. The X++ code in reports
must deal with the functionality for the specific report. All other X++
code must generally be implemented on the table to be reused by other
areas in the application. Here are some of the advantages to such an
approach:
Customizations made to a report are
isolated; customizations made to a table affect all reports using that
table, resulting in a consistent user experience wherever the table is
used.
Customization of a report copies
the entire report to the current layer; customizations made to tables
are more granular because customization of fields, field groups, and
methods results in a copy of the specific element to the current layer
only. This makes upgrading to service packs and new versions easier.
Methods
in reports always execute on the tier where the report is generated;
methods on tables can be targeted to execute on the server tier. Where a
report is generated is controlled by the RunOn property on the menu item that starts the report. The property can be set to Client, Server, or Called From.
1. Creating Promotional Materials
The example in this section demonstrates how to
customize the sales order invoice report named SalesInvoice
(AOT\Reports\SalesInvoice). The invoice is customized to include
promotions based on items listed on the invoice. The promotion appears
below each item on the invoice associated with a promotion. Figure 1 shows an example of an invoice that displays a promotion for a water bottle.
Like
the forms example, this example uses the document management feature in
Dynamics AX. You use document handling to store the text and image in
the database. The information is attached to the item table as two
different types of document information, named PromoText and PromoImage, for storing the text and image. Figure 2 shows the PromoText and PromoImage document types.
Figure 3 shows the text and image attached to an item named PB-Bike.
The X++ code used to display the promotion on the invoice looks up the item in the InventTable table and searches the document handling for documents of type PromoText and PromoImage to print on the invoice. If neither type is attached to the item, no promotion information prints.