In this walkthrough, you will create a non-printing report.
Although you can achieve the same functionality by writing a
codeunit, there are several reasons for using non-printing
reports:
-
The functionality that is available through a request form that
prompts for options and filters is achieved with less effort than
recreating the functionality in a codeunit using C/AL code.
-
Using the features of Report Designer to prompt for options and
to set filters ensures consistency in the application that you are
creating.
-
Instead of writing C/AL code to open tables and retrieve
records, you only need to define a data item.
This report is simple—it adjusts prices in the Item table. Users
can set filters on fields in the table to select a range of items
by number, posting group, or vendor, and then choose the factor by
which to adjust the prices.
Prerequisites
To complete this walkthrough, you will need:
Defining the Data Model
This report has one data item that is based on the Item
table.
To define the data model
-
Open Report Designer and create a new blank report.
-
Create a data item based on the Item table.
-
Open the Properties window of the report and set the
value of the ProcessingOnly property of the report to
Yes.
-
Open the Properties window of the data item and use the
AssistButton to set the value of the
DataItemTableView property to No..
Note |
Though this is not necessary for the functionality of the
report, it removes the Sort button from the request form
that is presented to the user when they want to run the report.
|
-
Use the AssistButton in the ReqFilterFields
property to select the fields that the users can filter by.
-
Declare the following variables
Name |
Datatype |
Description |
Window
|
Dialog
|
Prints a screen message.
|
Adjustment
|
Decimal
|
Used for the value that the user enters in the request form.
|
NewPrice
|
Decimal
|
Used to store an intermediate result.
|
Creating a Request Form
In the previous procedure you created a request form that
contains a tab where you can set filters on some of the fields in
the data item. You must now add an Options tab, where you can
define the adjustment factor.
To create an options tab
-
Click View, and then click Request Form to open
Request Options Form Designer.
-
Add a text box with a label to the form. To have the label added
automatically, click the Add Label button in the
Toolbox before selecting the Text Box tool.
-
In the Properties window of the text box, set the value
of the SourceExpr property to Adjustment, the
variable you have just created.
Using the Triggers
Now that you have defined the data model and designed the
request form, you need to add C/AL code to the triggers of the Item
data item to perform the actual price adjustment.
To use the triggers
-
Open C/AL Editor.
-
In the OnPreDataItem() trigger, enter the following lines
of code.
|
Copy Code |
Window.OPEN('Processing item #1#########');
If Adjustment = 0 THEN
CurrReport.QUIT;
|
-
In the OnAfterGetRecord() trigger, enter the following
lines of code.
|
Copy Code |
Window.UPDATE(1,"No.");
NewPrice := Adjustment x "Unit Price";
VALIDATE("Unit Price", NewPrice):
MODIFY;
|
-
Close the C/AL Editor window and save the report.
The code that you added to the triggers works like this:
-
The first statement in the OnPreDataItem
trigger
opens a progress window that shows the progress of the report as it
is run. Because the report is non-printing, the usual printing
progress window is not shown. If the table is large, the report may
run for a while. Therefore, it is a good idea to tell the user that
something is happening and show them how it is progressing.
-
The first statement in the OnAfterGetRecord
trigger
enters the item number in the window each time a new record has
been retrieved.
-
The second statement in the OnPreDataItem
ends the
report without doing any processing if the adjustment factor is 0
(zero). If the adjustment factor were allowed to be zero, all the
prices in the table would be set to zero. The statement used here
is a crude way of handling this. In a more polished version, you
would, for example, have a chance to reenter the adjustment factor
(or be notified of the reason for quitting the report).
-
The last three lines in the OnAfterGetRecord
trigger update the prices. First, the adjusted value is assigned to
the NewPrice
variable. Then, the VALIDATE
function of the Unit Price field is used to update the price. Any
special processing (for example, updating of related fields) in the
OnValidate
trigger of the table field is performed.
Finally, the MODIFY
function is used to commit the
change.
See Also