Passing DTO collection to report

I’m having problems sending my own list of DTO entities to a Jmix report. I create my list, run queries to populate certain attributes, and pass the collection as a parameter using uiReportRunner addparam.

In my report, I created a parameter as a “List of Entities” and chose my DTO entity. My report band has a dataset type “List of Entities,” I’ve selected my parameter name, and I’ve selected the attributes I want from the DTO.

When I run the report, I receive a dialog “An error occurred while generating report” while loading data for the band, query and report name. It simply states: “No results.”

What I suspect is happening is that the report runner is attempting to run a query. I need to report on a DTO collection that I’ve created in code. Is it possible to do that? Perhaps I’ve overlooked something in the documentation.

Thanks in advance for any guidance you can provide.

The reporting engine reloads the entities passed as “Entity” or “List of entities” parameters from the database, so only JPA entities can be passed this way and used in the “Entity” and “List of entities” datasets.

If you want to print a list of DTOs passed to the ReportRunner, use a Groovy dataset and just transform the list of entities to the list of maps:

return params['entities'].collect {[
    'title': it.title,
    'description': it.description
]}

And don’t declare your parameter in the Parameters and Formats editor, it is needed only to request input from the user.

1 Like

Thank you! That appears to do exactly what I need.

How we can add DTO entity (not JPA entity) to create report?

I’m new at this and not the most qualified to answer. However, I simply passed my DTO entity collection (named “categories”) as a parameter. I was then able to access the collection via Groovy as Konstantin described:

    uiReportRunner.byReportCode("status-of-funds")
            .addParam("categories", categories)
            .withTemplateCode("sof-template")
            .withOutputType(ReportOutputType.XLSX)
            .withOutputNamePattern(outputName)
            .withParametersDialogShowMode(ParametersDialogShowMode.NO)
            .runAndShow();
2 Likes