Reporting on an ordered collection
OrderedCollection has been enabled for reporting by adding an attribute to its public interface called iterator, which returns a read stream on the ordered collection. The iterator, in turn, has an attribute called current, which represents the current item in the collection. To report on an ordered collection, you can generate a quick report iterator for the current of iterator attribute.
For the sample business expense application, you will need to work with two ordered collections, which will be connected: The OrderedCollection in BusinessExpenseView, which you named BusinessExpenseCollection, and an OrderedCollection variable in the report part.
Adding an ordered collection to the report
1. In the Composition Editor for BusinessExpenseReport, select Variable from the Models category and drop the variable on the free-form surface.
2. Change the variable's type to OrderedCollection and change its name to Expenses.
Use the Change Type and Change Name choices on the variable's pop-up menu to change these values
3. Before you can report on ordered collection parts, you need to make sure that your report part can access the attributes (the instance variables) of the BusinessExpense object contained in the ordered collection. You do this by defining BusinessExpense as the contents of Expenses.
4. From the Expenses variable's pop-up menu, select Change Contents Type and type BusinessExpense in the window that displays.
This step indicates what type of object (business expense) the ordered collection contains.
5. Promote Expenses to the public interface of BusinessExpenseReport with the name expenses.
6. Save BusinessExpenseReport.
Connecting the OrderedCollection variables
Switch back to the Composition Editor for BusinessExpenseView and connect the self attribute of BusinessExpenseCollection to the expenses attribute of the report part in the Composition Editor.
Generating report fields
1. Now return to the Composition Editor on BusinessExpenseReport, drop a new report line on the body of the report shell, and delete the default text field.
2. From the pop-up menu of the Expenses variable, select Quick Report and then iterator.
A window displays listing the attributes of BusinessExpense.
3. Select the airfare, date, meals, misc, reason, and room attributes.
4. Drop the report fields on the new report line.
5. To make your report look nicer, rearrange and align the fields as shown in the following illustration. You can also open the settings for the numeric fields and set their converters to Monetary Amount.
6. Add a Report Text Field to the footer section of the iterator and change its text to Column totals.
7. For a business expense report, a grand total is more meaningful than a record count field. You can change this part of the report as follows:
a. Change the Count text field to Total expenses.
b. Open the settings of the [count] calculated field and select total from the displayAttribute drop-down list.
c. Save the settings and connect the formatted events of the [airfare], [room], [meals], and misc], fields to the countObject action of the calculated field.
The formatted event is signaled when the information in a field had been formatted. You use this event to trigger a calculation to ensure that a value has been supplied for the field.
8. Save the report part.
Now your report has a Report Iterator part with connections to the Expenses variable representing each of the attributes of a BusinessExpense. The Report Iterator has three sections:
• A header with a label for each attribute.
• A body with a Report Text Field for each attribute.
• A footer with one Report Calculated Field that calculates the total for each numeric attribute and one Report Calculated Field that counts the number of items in BusinessExpenseCollection.
This section of the report looks like this in the Composition Editor:
Last modified date: 05/18/2020