Running Reports
Running from Reports Browser
The easiest way to run reports is from the generic browser, which is available in the Reports → Run Reports screen. The user must have the right to access this screen. The list will contain all reports that are available to the user in accordance with their role. If the report has external parameters, they will be requested in a special form when running the report.
Running from Screens
You can run reports from arbitrary screens using special actions and associated buttons or component context menu items. In this case, the availability of the report directly in this screen is checked in addition to a user role.
Action types and examples of their use are provided below.
-
io.jmix.reportsui.action.list.RunReportAction
– a standard action that displays the list of all available reports. It should be defined for aButton
or a list component (Table
,DataGrid
, etc.).Below is an example of using the declarative action for the
GroupTable
:<actions> <!-- ... --> <action id="run" type="runReport"/> (1) </actions> <!-- ... --> <button id="runBtn" action="booksTable.run"/> (2) </buttonsPanel>
1 - the type
attribute defines a specificrunReport
action type, provided by the framework.2 - add a button with run report action. Example of programmatically creating the action together with a button declared in the screen XML descriptor:
@Autowired private Button runReportBtn; @Autowired private Actions actions; @Subscribe public void onInit(InitEvent event) { RunReportAction action = actions.create(RunReportAction.class, "runReport"); runReportBtn.setAction(action); }
When the action is performed, a modal Report Run dialog will open where reports related to the current screen will be displayed. When a user selects a report from the list, the parameters input form is displayed (if any were defined) and the report is run.
-
io.jmix.reportsui.action.list.ListPrintFormAction
– a standard action for printing reports for entity instances associated with a list component (Table
,DataGrid
, etc.).The action only selects reports having an external parameter of the Entity or the List of entities type and where the parameter entity type matches the entity type displayed by the list component. If only one report is available as a result of selection, it is invoked immediately. If several reports are available, their list is offered to the user for selection.
The external parameter value is passed to the report using the following rules:
-
If the parameter has the List of entities type, the list of instances currently selected in the list component is passed into it.
-
If the parameter has the Entity type, and the list component has a single instance selected (one row is highlighted), then this instance is passed into the report.
-
If the parameter is of the Entity type, and the list component has several rows selected, then the report runs several times according to the number of selected instances. After execution, the user gets a single ZIP archive containing all generated reports.
Below is an example of using the declarative action for the
GroupTable
:<actions> <!-- ... --> <action id="list" type="listPrintForm"/> (1) </actions> <buttonsPanel id="buttonsPanel" alwaysVisible="true"> <!-- ... --> <button id="listBtn" action="authorsTable.list"/> (2) </buttonsPanel>
1 - the type
attribute defines a specificlistPrintForm
action type, provided by the framework.2 - add a button with run report action. Example of programmatically creating the action together with a button declared in the screen XML descriptor:
@Autowired private Button listPrintFormBtn; @Autowired private Actions actions; @Subscribe public void onInit(InitEvent event) { ListPrintFormAction action = actions.create(ListPrintFormAction.class, "listPrintForm"); listPrintFormBtn.setAction(action); }
When the action is performed, if no entities were selected from the list component, a confirmation window will be displayed.
Figure 1. A confirmation windowAfter that, the modal Run reports dialog will open where reports related to the current screen will be displayed. From this modal screen, the user can run some report for the selected entity.
-
-
io.jmix.reportsui.action.list.EditorPrintFormAction
– an action associated with an entity editor screen. The action only selects reports having an external parameter of the Entity or the List of entities type and where the parameter entity type matches the edited entity type. If only one report is available as a result of selection, it is invoked immediately. If several reports are available, their list is offered to user for selection.The external parameter value – edited entity instance – is passed into the report. If the parameter has the List of entities type, then a list containing a single item is passed.
Below is an example of using the action in a button located near the standard OK and Cancel buttons:
-
XML descriptor
<hbox id="editActions" spacing="true"> <!-- ... --> <button id="reportButton" icon="PRINT"/> </hbox>
-
Controller
@Inject private Button reportButton; @Autowired private Actions actions; @Subscribe public void onInit(InitEvent event) { EditorPrintFormAction action = actions.create(EditorPrintFormAction.class); action.setEditor(this); action.setReportOutputName(null); reportButton.setAction(action); }
-