## Special fields

Special fields are defined by JReport and allow you to easily obtain system information and report-related data and add it to your report. The special fields are as follows:

- Print Date
  Prints today's date (or the current date from your computer).
- Print Time
  Prints the current time from your computer.
- Fetch Date
  Prints the date when the data is retrieved from the database.
- Fetch Time
  Prints the time when the data is retrieved from the database.
- Record Number
  Prints the record number (usually placed in the Details panel).
- Group Name
  Prints the group name (usually placed in the Group Header/Footer panel).
- Total Records
  Prints the total number of records after all the filter conditions are performed, except the ones created in the Filter dialog of JReport Web, and the Group Filter dialog and top N or bottom N condition in JReport Designer.
- Total Fetched Records
  Prints the total number of records which take part in grouping calculation. The possible result of the special field is as follows:
  - If you don't set any filter condition in the Filter dialog of JReport Web, print the very number of the record obtained after setting the property Maximum Records.
  - If you set filter conditions in the Filter dialog of JReport Web, print the number of records obtained after performing the filters, even though you have set the property Maximum Records before setting the filters.
- Group Number
  Prints the group number (usually placed in the Group Header/Footer panel).
- Total Group Number
  Prints the total group number (usually placed in the Group Header/Footer panel).
- Page Number
  Prints the page number of the report which it is placed in.
- Global Page Number
  Prints the global page number of the whole report wherever it is placed.
- Total Page Number
  Prints the total page number of the report which it is placed in.
- Global Total Page Number
  Prints the global total page number of the whole report wherever the field is placed.
- SQL Statement
  Prints the SQL statements used to execute the query.
- User Name
  Prints the User ID used when logging onto JReport Enterprise Server. When viewing the report in JReport Designer, it will return NULL, while when running the report on JReport Enterprise Server, it will return the name used to log onto the Server. The User Name special field can be used in different data sources as follows:

  | Where Condition of Query | HDS (General) | HDS (XML) | UDS | SQL File
  --- | --- | --- | --- | --- | ---
  User Name | Supported. | Supported in the Parameter box in the Add General Hierarchical Data Source dialog. | Supported. | Supported in the Parameters box in the Add User Data Source dialog. | Supported in the SQL statement.
  User Name used in a formula | Supported. | Supported. | Supported. | Supported. | Supported.

- Modified Date
  Prints the last modified date of the catalog.
- Modified Time
  Prints the last modified time of the catalog.
- Task ID
  Prints the internal task ID (a unique time stamp). This special field only works in the JReport Enterprise Server environment. It returns a NULL value when running in JReport Designer.
- Page N of M
  Prints a specific page number out of the total page number of the report which the field is placed in. You can specify the format of this special field. To do this, select this special field, then in the Report Inspector, find the Format property and choose an item from the shortcut list. Besides the items listed here, you can also customize the format. For example, if you want it displayed as "This is page n of m pages", you can input the format string "This is page @PageNumber of @TotalPageNumber pages" into the Format text box.
- Global Page N of M
  Prints a specific global page number out of the global total page number. You can specify the format of this special field in the Report Inspector. The operation is the same as Page N of M.

Note: Page Number, Total Page Number and Page N of M in the following conditions in versions after V8 are different from those in versions prior to V7:

- In V7 and prior, the Page Number, Total Page Number and Page N of M which are placed in a subreport will calculate the page number of the subreport if the value of the property Embed in a subreport is set to true. And if you set Embed to false, the Page Number, Total Page Number and Page N of M will work as global special fields, it will calculate the page number of the main report.
- While in V8 and after, the Page Number, Total Page Number and Page N of M which are placed in a subreport will calculate the page number of the subreport no matter you set the property Embed to true or false.

### Referencing special fields in a formula

Some special fields can be used in formulas. They are User Name, Print Date, Print Time, Fetch Date, Fetch Time, Modified Date, Modified Time, Record Number, Page Number, Global Page Number, Total Records and Total Fetched Records. They can all be divided into two types (page level and constant level) according to the time when their values are ready.

Page level

The value of this special field is ready at the time when the report result is generated. A formula which references a page-level special field is treated as a page-level formula. In which, the formula is calculated more than once.

The special fields of this type are: Fetch Date, Fetch Time, Record Number, Page Number, Global Page Number, Total Records and Total Fetched Records.

Constant level

The value of this special field is ready at any time before the engine runs. A formula which references a constant-level special field is treated as a constant-level formula, and is calculated only once.

The special fields of this type are: User Name, Print Date, Print Time, Modified Date and Modified Time.

### Inserting a special field into a report

Special fields can be inserted in the report areas listed in Component placement.

To insert a special field into a report:

1. Position the mouse pointer at the destination where the special field is to be inserted.
2. Do one of the following:
   - Click Insert > Special Fields, and click the corresponding command on the submenu.
   - Click the down arrow on the Insert Special Field button on the Insert toolbar and select the required special field from the drop-down list.
3. Click in the destination to insert the special field.

When a special field has been inserted into a report, you can customize its appearance and behavior by setting properties in the Report Inspector, which can be saved as a CSS style for future use (for details, see Creating a CSS style).

### Changing the display type of a special field

The display type of a special field can be changed according to your requirements, that is to say, you can map the special field to another value or image to be displayed instead.

To change the display type a special field:

1. Right-click the special field and select Display Type from the shortcut menu.
2. In the Display Type dialog, specify the required display type in the Type box and set the options for the selected type in the Option panel.
3. Upon finishing, click the OK button to close the dialog.

For details about display types, see Changing the display type of a label.

### Binding a link to a special field

You can make a special field linked with another report, a URL or an e-mail. To do this:

1. Right-click the special field and select Detail Report on the shortcut menu to display the Master/Detail Report dialog.
2. From the Link to drop-down list, specify the target to which the special field will be linked.
3. Set the options for the target according to your requirements.
4. When done, click OK.

For details about different link targets, see Binding a link to a label.

### Adding conditional formats to a special field

You can add some conditional formats to a special field, then when the specified condition is fulfilled, the defined format will be applied to the field values for distinguishing. However, conditional formatting applies only to the two special fields: Page Number and User Name.

To add conditional formats to the special field Page Number/User Name:

1. Right-click the special field and select Conditional Formatting from the shortcut menu.
2. In the Conditional Formatting dialog, click the button to add a condition as required.
3. Set the format that will be applied to the field values when the specified condition is fulfilled.
4. Repeat the above two steps to add more conditions and define the format for each condition as required.
5. When done, click OK to save the settings.

For more details about conditional formatting, see Adding conditional formats to a DBField.

See an example: The SampleComponents catalog, included with JReport Designer, contains reports that have examples of how each component type could be used in a report. For the special field example, open `<install_root>\Demo\Reports\SampleComponents\ForSpecialFields.cls`.