Hi,
I’m trying to run a report by clicking on the custom button that I’ve added near the table actions button.
The code that supposed to run the report looks like that:
@Override
public void init(Map<String, Object> params) {
super.init(params);
reportBtn.setAction(new RunReportAction("report"));
TablePrintFormAction action = new TablePrintFormAction("report", table);
table.addAction(action);
reportBtn.setAction(action);
}
The problem is that when I try to run it by clicking on the button a notification is shown and says that there are no reports for the screen I’m working on.
Of course, there is a report for the entity that I’d like to run the report and I followed the documentation in order to add this functionality but for some reason, it doesn’t work.
Link to documentation page that I’ve been using: Running Reports from Screens - CUBA Platform. Report Generator
Creating a report with wizard:
Selecting attributes:
Saving the report:
Trying to run the report from “Report” section:
Selecting entries that I want to be printed:
Everything is fine:
As you can see, the report I just created doesn’t show when I try to run it from screen controller:
I also tried to use another approach:
print method related to the button’s invoke preperty in the xml file.
public void print() {
List<Report> reports = reportGuiManager.getAvailableReports(getId(), userSession.getUser(), processingActivityDs.getItem().getMetaClass());
if (reports.size() > 1) {
openLookup("report$Report.run", items -> {
if (!items.isEmpty()) {
Report report = (Report) items.iterator().next();
runReport(report);
}
}, WindowManager.OpenType.DIALOG, ParamsMap.of(ReportRun.REPORTS_PARAMETER, reports));
} else if (reports.size() == 1) {
Report report = reports.get(0);
runReport(report);
} else {
showNotification(messages.getMessage(ReportGuiManager.class, "report.notFoundReports"),
NotificationType.HUMANIZED);
}
}
private void runReport(Report report) {
ReportInputParameter parameter = report.getInputParameters().stream()
.filter(inputParam -> reportGuiManager.parameterMatchesMetaClass(inputParam, processingActivityDs.getItem().getMetaClass()))
.findFirst()
.orElseThrow(() -> new ReportingException("No suitable report parameter found"));
ReportOutputDocument reportResult =
reportGuiManager.getReportResult(report, ParamsMap.of(parameter.getAlias(), processingActivityDs.getItem()), null);
showOptionDialog("Print options", "What do you want to do with the report?",
MessageType.CONFIRMATION, new Action[]{
new AbstractAction("show", Action.Status.PRIMARY) {
{
setCaption("Show");
}
@Override
public void actionPerform(Component component) {
exportDisplay.show(new ByteArrayDataProvider(reportResult.getContent()),
reportResult.getDocumentName());
}
},
new AbstractAction("download") {
{
setCaption("Download");
}
@Override
public void actionPerform(Component component) {
exportDisplay.show(new ByteArrayDataProvider(reportResult.getContent()),
reportResult.getDocumentName(), ExportFormat.OCTET_STREAM);
}
},
new DialogAction(DialogAction.Type.CANCEL)
});
}
But it as result it says that there are no reports for the screen.
Thanks in advance.
Any help will be appreciated.