“I want to allow my users to enter their comment from the report UI and print it in the report along with the reporting data.”
“I want to change the calculation or condition logic based on the user’s selection or inputs at the runtime.”
These are the questions I hear once in a while and the short answer is ‘Yes’. For example, you can do something like below, which users type their comment and generate the report with the comment.
BI Publisher supports Parameter functionality, which allows the end users to select or enter values when they open the reports and filter the reporting data based on the input values.
As a report developer you can pass this value to the underlying data source such as SQL query and filter the data result. For example, in order for you to pass this user input values and filter the data you can create a parameter called ‘param1’ and add the parameter value prefixing with ‘:’ into a WHERE clause. (e.g. where department_id = :param1)
Now, how about passing the user input values to the layout template instead of to the SQL query ? Yes, you can pass the values to your template and use the values in your condition, calculation, or just to display it in the report output.
It’s pretty simple, but there are a couple of steps to follow.
Create Parameter at BI Publisher Server UI
This is no brainer. You can just go to the Report edit window and create a report parameter from the UI.
Please see the Reports Designer’s guide for the detail.
Declare Parameter in RTF Template
Before you use the parameter in the RTF template file you need to declare it first. You can do so by having the following syntax.
Note: where %parameter_name% is the parameter name that you have created at the BI Publisher Server UI.
Here is an example:
Use it in RTF Template!
Once it’s declared in the RTF template you can start using it as the same way you use the variable. You need to just add ‘$’ prefix in front of the parameter name. Here is the example:
The above example would print the parameter value in the report output. If you want to use this value in your condition or calculation you can simply use it as ‘$param1’. Yes, it’s that simple.
If you are not sure if and how the parameter values are passed to the report when you run the report you can use this command in your RTF template, which will return all the parameter values passed to the RTF template at the runtime.
Note that the above command has been introduced relatively new so if you’re running on an older version of BI Publisher it might not work.
Anyway, so now you know the steps involved to get the user input values and use it within your RTF template. Have fun!