Reports Information
You can use Report Text Fields and scripts to make more
complex calculations than those provided by the Report Calculated
Field. The following illustration shows the same report as in the
previous section, but with a new column showing commissions as a percentage of
salary. In the footer section of the field break, the average
commission rate for each job type is shown, and in the footer section of the
iterator, the average commission rate for all employees is shown.

To add this column, follow these steps:
- Add the following fields to the report iterator:
- A Report Text Field with the text Average % to the header
section.
- A Report Text Field to the body section. (Make no changes to it for
now.)
- A Report Calculated Field to the footer section of the field break.
- A Report Calculated Field to the footer section.
- Align the fields in this new column as you did in Adding field breaks to an iterator.
- Open the settings for the two Report Calculated Field parts and change the
displayAttribute property to average.
- Switch to the Script Editor and write the following script:
commissionAsPercentage
"Calculates the commission as percentage of salary"
((self subpartNamed: 'COMMField') object = nil) ifTrue: [^0].
^(((self subpartNamed: 'COMMField') object)
asDecimal) /
(((self subpartNamed: 'SALARYField') object)
asDecimal).
- Switch back to the Composition Editor and connect the formatted
event of the [COMM] field to the script.
- Connect the normalResult attribute of the script to the
object attribute of the new text field in the body section of the
iterator.
Note: | Notice that the field changes to [normalResult].
|
- Now make two connections from the [normalResult]
field:
- Its formatted event to the countObject action of the
Report Calculated Field in the footer section of the field break.
- Its formatted event to the countObject action of the
Report Calculated Field in the footer section of the iterator.
- Change the converter for the normalResult text
field, and the two [average] fields to decimal, with a
decimalPlace value of 2.
Your report should appear similar to the following in the Composition
Editor.

When you test your report and select Preview from the
Reports menu of the Report Tester, it should look very similar to
the example at the beginning of this section.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]