Reports - Change default value in Parameter

Hi JMIX Team,

We are using JMIX v2.3 and the Reports addon, we have a report that we can run by month and year, we would like to set the default value to the last month and year stored in the the database, we want to do it dinamically but we didn´t find how to do it. It seems that currently only a fix default value is allowed.

Is there any way to make that possible?

Year and Month

Hello @lgarciaga

You can open the ‘Run report’ dialog from the code. To do this, you need to call the generation of a report using the UIReportRunner bean component.

For example:

    @Subscribe(id = "runReport", subject = "clickListener")
    public void onRunReportClick(final ClickEvent<JmixButton> event) {
        uiReportRunner.byReportCode("test-report")
                .withParams(Map.of("name", "Value")) //Set a parameter
                .withOutputType(ReportOutputType.XLSX)
                .withOutputNamePattern("test-report.xlsx")
                .withParametersDialogShowMode(ParametersDialogShowMode.IF_REQUIRED)
                .inBackground(this)
                .runAndShow();
    }

You can create this method using code snippets. :upside_down_face:
image

Result
image

Regards,
Nikita

Hi Nikita,

Thanks for the hint and information about the UIReportrunner, but we would like to use the standard report run view (image below) because our users need to run many different reports. We do not want to create one view per report. Is there any way to change the parameter when we run from the standard view or we need to create a customer one to make this happen.

runreport

Thank you

The standard “Run Report” screen also uses UIReportRunner. You can override the screen and add the parameter in the method.

For example:

image

image

@Route(value = "reports/run", layout = MainView.class)
@ViewController("report_ReportRunView")
@ViewDescriptor("ext-report-run-view.xml")
public class ExtReportRunView extends ReportRunView {

    @Override
    protected void onReportDataGridRunReport(ActionPerformedEvent event) {
        Report report = reportDataGrid.getSingleSelectedItem();
        if (report != null) {
            report = dataManager.load(Id.of(report)).fetchPlan("report.edit").one();
            FluentUiReportRunner fluentRunner = uiReportRunner.byReportEntity(report)
                    .addParam("name", "Value") //Set the parameter
                    .withParametersDialogShowMode(ParametersDialogShowMode.IF_REQUIRED);

            try {
                if (reportsClientProperties.getUseBackgroundReportProcessing()) {
                    fluentRunner.inBackground(this);
                }

                fluentRunner.runAndShow();
            } catch (MissingDefaultTemplateException var5) {
                notifications.create(messages.getMessage("runningReportError.title"), messages.getMessage("missingDefaultTemplateError.description"))
                        .withType(Notifications.Type.ERROR)
                        .show();
            }
        }
    }
}

Regards,
Nikita