Formula Fields
Formula fields are calculated from DBFields, other formulas, summaries, and parameters, so they can present information that DBFields cannot do.
Below is a list of the sections covered in this topic:
Inserting a Formula Field in a Report
A formula field can be inserted in the report areas listed in Component placement.
- For a business view based report
Select the formula from the Dynamic Resources > Formulas node in the Data panel and drag it to the destination. - For a query based report
You have two ways to insert a formula into a query based report.- By dragging and dropping
Select the formula from the Formulas node in the Data panel, then drag it to the destination. If the given formulas are not what you want, select the <New Formula...> item to create one as required. - Using dialog
- Position the mouse pointer at the destination where you want to insert the formula and select Insert > Formula or Home > Insert > Formula.
The Insert Fields dialog appears.
- Select the required formula from the Formulas node, then specify its layout in the Insert Layout box.
- Select the Insert button to insert the formula into the destination.
- Position the mouse pointer at the destination where you want to insert the formula and select Insert > Formula or Home > Insert > Formula.
- By dragging and dropping
Notes:
- In a query based report, not all formulas in the catalog are valid in the current context, so under the Formulas node in the Insert Fields dialog or the Data panel, only the valid formulas that are based on DBFields from the current dataset are listed.
- If you insert a formula into the detail panel of a component, the name of the formula will automatically be inserted as a label into the corresponding header panel. Otherwise the formula and its name label will be placed in the same panel. If you do not want to insert the name label automatically, you can uncheck Insert field name label with field in the Options dialog (File > Options > Component > Insert field name label with field).
Changing the Display Type of a Formula Field
The display type of a formula field can be changed, that is to say, you can map the formula field to another value or image to be displayed instead.
To change the display type a formula field:
- Right-click the formula field and select Display Type from the shortcut menu.
- In the Display Type dialog, specify the required display type in the Display As box, and set the options for the selected type in the Web Options panel.
- Upon finishing, select the OK button to close the dialog.
For details about display types, see Changing the Display Type of a Label.
Applying Web Actions to a Formula Field
A formula field can be bound with web actions. This allows you to customize a formula field to make it respond to interactive events, and execute corresponding actions, such as sorting and filtering.
To apply web actions to a formula field:
- Right-click the formula field and select Display Type from the shortcut menu.
- In the Web Behaviors box of the Display Type dialog, choose an event from the Events column, then select in the Actions column and select that appears in the text box.
- In the Web Action List dialog, select a web action and define the action as required.
- Select in the Display Type dialog to add more web behavior lines and specify the events and actions accordingly. If a web behavior is not required, select to remove it.
- Adjust the order of the added web actions by selecting or . Then, when an event that has been bound with more than one action happens, the upper action will be triggered first.
- When done , select OK to accept the settings.
For more information about web actions, see Applying Web Actions to a Label.
Binding a Link to a Formula Field
You can make a formula field link to another report, a location specified by a URL, an e-mail address, or a Blob data type field. The link can either be a simple link or a conditional link. With conditional links, different targets can be loaded based on different conditions.
To bind a link to a formula field:
- Right-click the formula field and select Link on the shortcut menu.
- In the Insert Link dialog, specify whether it is a conditional link or a simple link, then select the link target and set the options for the link target as required.
- When done, select OK.
For details about different link targets, see Binding a Link to a Label.
Adding Conditional Formats to a Formula Field
You can add conditional formats to a formula field, then when a specified condition is fulfilled, the format bound with the condition will be applied to the field values automatically. This is very useful to highlight values that might need to be acted on by the end user.
To add conditional formats to a formula field:
- Right-click the formula field and select Conditional Formatting from the shortcut menu.
- In the Conditional Formatting dialog, select the button to add a condition.
- Set the format that will be applied to the field values when the specified condition is fulfilled.
- Repeat the above two steps to add more conditions and define the format for each condition.
- When done, select 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 Logi JReport Designer, contains reports that have examples of how each component type could be used in a report. For the formula field example, open <install_root>\Demo\Reports\SampleComponents\UsingFormula.cls
.