## Using dynamic resources in a library component

When working with a library component, sometimes you may find the predefined view elements in the business view on which the library component is based cannot meet your requirements. In this case, you can create some dynamic resources and use them in the library component to get the desired data. Then when you save the library component, the dynamic resources will be saved along with it as its resources.

Dynamic resources are library component level resources, which means they are only available to the library component for which they are created.

Dynamic resources that can be used in library components include formulas and aggregations.

### Creating and using dynamic formulas

To create a dynamic formula:

1. In the Resource View panel of the main window, or in the Resources box of the report wizard, expand the Dynamic Resources > Formulas node, click <Add Formula…>.
2. In the Input Formula Name dialog, specify the name of the formula and click OK. The Formula Editor appears.
3. Create the formula according to your requirement.
4. From the Use As drop-down list on the toolbar, specify whether the formula is used as Group, Detail or Aggregation.

   Whether a dynamic formula can be used as a certain type depends on the following rule:

   - Any formula can be used as Detail.
   - Record level pass one formula can be used as Group.
   - Comparable and record level pass one formula can be used as Group.
   - Group level formula can be used as Aggregation.
5. Save the formula and exit the Formula Editor.

Once a dynamic formula has been created, you can then drag it from the Resource View panel to the desired position in the library component as a detail/group or an aggregation object as defined, or use it when working with the report wizard.

In the Resource View panel, you can make use of the shortcut menu of an existing dynamic formula to edit or delete the formula, or change the formula type as Group, Detail, or Aggregation if needed.

Notes:

- You can only use JDK (not JRE) to compile formulas created in JReport and save a dynamic formula with no errors into a library component.
- Currently, global variables are not supported in dynamic formulas.
- When dynamic formulas reference display names or mapping names, the names should not contain any of the following characters if the names are not quoted by double-quotation marks "":

  "~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+", "=", "{", "}", "[", "]", "|", "\\", ":", ";", "\", " ' ", "<", ",", ">", ".", "?", "/"

  Examples:

  - Expression @Customer#; will cause a syntax error. But @"Customer#" is ok.
  - If a field has the display name Category.Aggregation, when adding it to a formula, quote it as "Category.Aggregation" or "Category"."Aggregation".

### Creating and using dynamic aggregations

You can also create dynamic aggregations by mapping them to the available resources such as group objects, detail objects in the current business view, and the dynamic formulas that have been created in a library component.

To create a dynamic aggregation:

1. In the Resource View panel of the main window, or in the Resources box of the report wizard, expand the Dynamic Resources > Aggregations node, then click <Add Aggregation…>. The Add Aggregation dialog appears. See the dialog.

2. In the Aggregation Name text field, specify the name of the dynamic aggregation.
3. Click next to the Mapping Name text field to specify the field on which the dynamic aggregation is based.
4. From the Aggregate Function drop-down list, specify the aggregate function.
5. When done, click OK to create the dynamic aggregation.

Once a dynamic aggregation is created, you can then drag it from the Resource View panel to the desired position in the library component to get the desired data, or use it when working with the report wizard.

For any dynamic aggregation, you can further modify if needed. To do this, right-click the aggregation and select Edit from the shortcut menu. Then in the Edit Aggregation dialog, edit the aggregation as required.

For dynamic aggregations that are no longer required, you can remove them. To delete an aggregation, right-click it and click Delete on the shortcut menu. Aggregations that have been used in the library component cannot be deleted.