Report from editor screen

Hi
I have created YARG report using excel template using the wizard.

The objective is to print Invoice from invoice entry Editor screen when it is saved.
I have generated the attached report template as downloaded from my application.
Report for entity Retail Invoice.zip (16.2 KB)

What happens is that, when I am in the retailInvoice.editor screen and click the button it shows message “there are no reports for this screen”.

Here is my code:

  public void print() {
    List<Report> reports = reportGuiManager.getAvailableReports(getId(), userSession.getUser(), 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, getItem().getMetaClass()))
            .findFirst()
            .orElseThrow(() -> new ReportingException("No suitable report parameter found"));

    ReportOutputDocument reportResult =
            reportGuiManager.getReportResult(report, ParamsMap.of(parameter.getAlias(), 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)
            });
}

Based on the message, it seems the reportGuiManage is unable tp file the report for the entity.

Thanks for your help CUBA team.

Hi,

Method com.haulmont.reports.gui.ReportGuiManager#getAvailableReports - return list of reports, available for a certain screen, user and input parameters. So you can configure Report Access Rights (Report Access Rights - CUBA Platform. Report Generator).

Hi Andrey
Thanks. Note that I get this error even when logged in with admin.

Looking forward to hearing from you soon.

Mortoza

Hi,

You resolve reports by screen id, and the current editor screen should be specified for the report in the Roles and Screen tab. If no screen is specified, the report won’t be available from any screen for any user.

Thanks

Hi Andrey
Thanks for the clarification. I see there is a table in report editor where I have authorized the role/screen.

Now I get another problem, getting the following exception and seems report parameterization is not good as follows:

com.haulmont.yarg.exception.ReportingException: No suitable report parameter found
at com.company.invoiceprint.web.invoice.InvoiceEdit.lambda$runReport$2(InvoiceEdit.java:71)

The exception is thrown here:

private void runReport(Report report) {
    ReportInputParameter parameter = report.getInputParameters().stream()
            .filter(inputParam -> reportGuiManager.parameterMatchesMetaClass(inputParam, getItem().getMetaClass()))
            .findFirst()
            .orElseThrow(() -> new ReportingException("No suitable report parameter found"));

I have created a sample app as attached, thanks for checking and advising the fix.
invoiceprint.zip (93.4 KB)

Mortoza

Hi,

Method com.haulmont.reports.gui.ReportGuiManager#getAvailableReports - return list of reports with the minimal view (without parameters, templates and etc). You can reload report with edit view in that cases, e.g.

private void runReport(Report report) {
  report = dataManager.reload(report, "report.edit");
  ReportInputParameter parameter = report.getInputParameters().stream()
                .filter(inputParam -> reportGuiManager.parameterMatchesMetaClass(inputParam, 
                 getItem().getMetaClass()))
                .findFirst()
                .orElseThrow(() -> new ReportingException("No suitable report parameter found"));
   ...
}

Thanks,
Andrey

Thank you so much Adnrey