Using Dynamic Resources and Local Parameters
When you add fields to a report or use parameters to define filter conditions in a report, sometimes you may find that the view elements that have been predefined in the business view or the given parameters in the current catalog cannot meet your requirements. In those cases, you can create dynamic resources (including formulas and aggregations) and local parameters in the report and use them to get the desired data. Then when you save the report, the dynamic resources and local parameters will be saved along with the report as its resources.
Dynamic resources and local parameters are report level resources, which means they are only available to the report for which they are created.
Below is a list of the sections covered in this topic:
- Creating and Using Dynamic Formulas
- Creating and Using Dynamic Aggregations
- Creating and Using Local Parameters
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, see Formulas in the Logi JReport Designer User's Guide.
To create a dynamic formula:
- In the Resources panel of Web Report Studio or the Resources box in the Web Report Wizard, expand the Dynamic Resources > Formulas node, then select <Add Formula…>. The Formula Editor appears.
- Enter a name for the formula in the Formula Name text box.
- By default, Logi JReport will decide whether the formula can be used as an aggregation object, and if not, the formula will be used as a detail object. You can specify to use the formula as a detail, group, or an aggregation object, by selecting the corresponding view element type from the Use As drop-down list on the toolbar.
Whether a dynamic formula can be used as a certain type depends on the following rules:
- Any formula can be used as Detail.
- Any formula that references a DBField and not an aggregation can be used as Group.
- A formula that refers only to aggregations can be used as Aggregation. For example, there are two aggregations Sum_Total and Sum_Quantity, and you can create a formula
@"Sum_Total" / @"Sum_Quantity"
and use it as an aggregation. - A formula that follows the custom aggregation expression can be used as Aggregation.
- Compose the formula by double-clicking the required fields, functions including Logi JReport built-in functions and user-defined functions, and operators from the Fields, Functions and Operators boxes respectively. You can also write the formula by yourself in the editing box.
- Select the Check button to check whether or not the syntax of your formula is correct.
- When done, select the OK button to create the formula.
Once a dynamic formula is created, you can then drag it from the Resources panel to the desired position in the report for data analyzing, add it as report field when working with the report wizard, or use it to create expressions in the Formula Editor.
If you want to further edit an existing dynamic formula, remove any that is not required, or change the formula type as Group, Detail, or Aggregation if possible, right-click the formula in the Resources panel of Web Report Studio and then select the corresponding command on the shortcut menu. Dynamic formulas that have been used in the report cannot be deleted.
Using User-Defined Functions
When you create dynamic formulas to use in a report, if the built-in functions do not satisfy your requirements, you can make use of the User-Defined Function feature to create any functions as you want. Then when you save the report, the functions will be saved into the report as its resources the same as dynamic formulas. User-defined functions can also call other user-defined functions.
To create a user-defined function:
- In the Resources panel of Web Report Studio or the Resources box in the Web Report Wizard, expand the Dynamic Resources > User-Defined Functions node, then select <Add Function…>. The User-Defined Function Editor appears.
- Enter a name for the function in the Function Name text box.
- Compose the function by double-clicking the required fields, functions including Logi JReport built-in functions and other user-defined functions, and operators from the Fields, Functions and Operators boxes. You can also write the function by yourself in the editing box.
The function syntax is as follows:
arguments: VariableType1 VariableName1, VariableType2 VariableName2, ...;
For example,
arguments: integer age, string name;
An argument works the same as a local variable except that it is not allowed to assign any value to it, like
arguments: integer age=10;
.For more information about the syntax, see Formula Syntax in the Logi JReport Designer User's Guide.
- Select the Check button to check whether or not the syntax of your function is correct.
- Select the OK button to create the function.
The function is then available under the User-Defined Functions node in the Functions box of the Formula Editor and User-Defined Function Editor. You can call it in a dynamic formula or another user-defined function by double-clicking it.
Suppose a user-defined function named function1 is written as: arguments: integer age, string name;
, you can call it as follows:
@function1(25, "John Smith");
@'function1'(25, "John Smith");
@"function1"(25, "John Smith");
If you want to further edit an existing user-defined function or remove any that is not required, right-click the function in the Resources panel of Web Report Studio and then select the corresponding command on the shortcut menu. Functions that have been used in the report cannot be deleted.
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:
- In the Resources panel of Web Report Studio or the Resources box of the Web Report Wizard, expand the Dynamic Resource > Aggregations node, then select <Add Aggregation…>. The Add Aggregation dialog appears.
- In the Aggregation Name text box, specify the display name of the dynamic aggregation.
- Select next to the Mapping Name text box. In the Select Resource dialog, specify the field on which the dynamic aggregation is based.
- From the Aggregate Function drop-down list, specify the aggregate function. When DistinctSum is selected, you should select next to the Distinct On text box to specify one or more group and detail objects according to whose unique values to calculate DistinctSum using the Select Fields.
For the usage about each function, see Summary functions in the Logi JReport Designer User's Guide.
- When done, select 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 for data analyzing, add it as report field when working with the report wizard, or use it to create expressions in the Formula Editor. And if you want to edit any dynamic aggregation or delete it, right-click the aggregation and select Edit or Delete on the shortcut menu.
Creating and Using Local Parameters
When you use parameters to compose the filter conditions applied to a report, if the given parameters in the current catalog cannot meet your requirements, you can create local parameters to use in the report. The local parameters created for a report can also be added to the parameter controls and parameter form controls in the report, or referenced in dynamic formulas used in the report.
To create a local parameter and use it in a filter:
- When filtering a business view in the Query Filter dialog, or a data component using the Filter dialog, select the button and select <Add Parameter…> from the Local Parameters node of the value drop-down list.
The Add Parameter dialog appears.
- In the Name field, input a name for the parameter.
- Select a parameter type from the Value Setting drop-down list.
- In the value section, specify the parameter values as required. The section varies with the type you select from the Value Setting drop-down list.
- For Type-in Parameter:
- Specify the data type of the parameter value from the Value Type drop-down list.
- Select to add a value line, double-click in it and then type in a value of the specified data type.
If the parameter is of Date, DateTime, or Time type, you can also select the calendar button to set a date and time value.
- Repeat the above step to add more values.
To adjust the order of the values, select or ; to remove any unwanted value, select it in the list and then select .
- To make a value the default selected value for the parameter, select it from the list.
- For Bind with Single Column
Logi JReport provides a mechanism that links each value of the display DBField with the exact value of the bound DBField, so that when you select a value of the display field, the value of the bound field is actually sent to the query and filters the query result. This can help you bind the parameter to a DBField in order to provide a list of values for the report users to select which probably makes more sense. The selected value of the bound field will be used as the parameter value. For example, it might be confusing if you provide a list of customer ID numbers for the report users to select, since the ID numbers would probably mean nothing to them. In cases like this, it is better for you to display values of other fields, which would make more sense. For this case, you might prefer to display customer names instead of ID numbers. When the report users select a customer name from the list, its ID number is passed to the query as the parameter value so that the search criteria can be fulfilled.- From the Source drop-down list, select the required business view in the current data source from which to get data for the parameter. All the group and detail objects in the specified business view will be available for retrieving values for the parameter.
- Select a field from the Bind Column drop-down list. This field is used to filter the query when running a report with the parameter.
- If you want the values of another field to be displayed for the report users to choose from, select that field from the Display Column drop-down list.
Logi JReport provides a mechanism that links each value of the display field with the exact value of the bound field for a parameter, thus when you select a value of the display field, the value of the bound field is actually sent to the query and filters the query result. This can help you bind the parameter to a DBField in order to provide a list of values for report users to select which probably makes more sense. The selected value of the bound field will be used as the parameter value. For example, it might be confusing if you provide a list of customer ID numbers for users to select at runtime, since the ID numbers would probably mean nothing to them. In cases like this, it is better for you to display values of other fields, which would make more sense. For this case, you might prefer to display customer names instead of ID numbers. When the report users select a customer name from the list, its ID number is passed to the query as the parameter value so that the search criteria can be fulfilled.
- For Bind with Cascading Columns:
- From the Data Source drop-down list, select the required business view in the current data source from which to get data for the parameter. All the group and detail objects in the specified business view will be available for retrieving values for the parameter.
- Select to add a parameter row.
- Select in the Bind Column cell and select a field from the drop-down list.
- If you want the values of another field to be displayed for the report users to choose from, select in the Display Column cell and select that field from the drop-down list.
- Select in the Parameter cell to create the parameter. A name for the parameter will then be automatically added by Logi JReport.
- Repeat steps b to e to create more parameters. Make sure that the selected Bind Column fields are of cascading relationship one level by one level down. In this way, a group of cascading parameters are created.
To adjust the order of the parameters, select or ; to remove any unwanted parameter from the cascading group, select it and then select .
- For Type-in Parameter:
- In the Options box, set options for the parameter according to your requirements.
- When done, select OK to create the parameter. The parameter is added to the Local Parameters node in the Parameters list.
To further edit the parameter, right-click it in the list and select Edit from the shortcut menu. Then in the Edit Parameter dialog, edit the parameter as required.
To remove the parameter, right-click it in the list and select Delete on the shortcut menu.
- Finish defining the filter condition using the parameter.
- Select OK to apply the settings. The parameter is then listed in the Parameters panel and you can specify the parameter value in the panel to dynamically set the filter condition.
Notes:
- You can only use JDK (not JRE) to compile formulas and user-defined functions created in Logi JReport and save them with no errors into a web report.
- Currently, global variables are not supported in dynamic formulas and user-defined functions.
- If you refer to any field in a formula or user-defined function, the reference name for that field will be prefixed with an @ sign. If the field name contains spaces, the reference name will be quoted with double-quotation marks (""). For example, if the field name is Customer Name, then the reference name will be @"Customer Name".
- When formulas and user-defined functions 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, quote it as "Category.Aggregation" or "Category"."Aggregation".