### Using dynamic resources

When you add fields to a report, sometimes you may find that the view elements that have been predefined in the business view cannot meet your requirements, in which case, you can create some dynamic resources and use them in the report to get the desired data. Then when you save the report, the dynamic resources will be saved along with the report as its resources.

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

Dynamic resources that can be used in web reports include formulas and aggregations.

#### Creating and using dynamic formulas

You should have some knowledge of the formula syntax before you can successfully compose a formula with no errors. To learn the formula syntax, refer to Formula syntax.

To create a dynamic formula:

1. In the Resources panel of Web Report Studio or the Resources box of the Web Report Wizard, expand the Dynamic Resource > Formulas node, then click <Add Formula…>. The Formula Editor appears. See the editor.

2. Enter a name for the formula in the Formula Name text field.
3. From the Use As drop-down list, specify what element type the formula is used as: Group, Detail or Aggregation.

   Which type a dynamic formula can be used as depends on the following:

   - Any formula can be used as Detail.
   - Record level pass 1 formula can be used as Group.
   - Comparable and record level pass 1 formula can be used as Group.
   - Group level formula can be used as Aggregation.
4. Compose the formula by selecting the required fields, functions and operators from the Fields, Functions and Operators boxes. You can also write the formula by yourself in the editing box.

   For details about the functions and operators, refer to Built-in functions and Operators.

5. Click the Check button to check whether or not the syntax of your formula is correct.
6. When done, click the OK button to create the formula.

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

In the Resources panel of Web Report Studio, 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 possible.

Notes:

- You can only use JDK (not JRE) to compile formulas created in JReport and save a dynamic formula with no errors into a web report.
- Currently, global variables are not supported in dynamic formulas.
- When 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

In Web Report Studio, 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 the report.

To create a dynamic aggregation:

1. In the Resources panel of Web Report Studio or the Resources box of the Web Report Wizard, expand the Dynamic Resource > Aggregations node, then click <Add Aggregation…>. The Add Aggregation dialog appears. See the dialog.

2. In the Aggregation Name text field, specify the display name of the dynamic aggregation.
3. Click the button next to the Resource Name text field. In the Select Resource dialog, 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 Resources panel to the desired position in the report to see the desired data, or use it when working with the report wizard. And if you want to edit any dynamic aggregation or delete it, right-click the aggregation and click Edit or Delete on the shortcut menu.