Post-process report HTML

I have a question about reports. When I generate an HTML report, the result opens in my browser. This is good. However, I would like to be able to post-process the generated HTML report in my java code BEFORE it gets displayed or downloaded. Is there a hook to access the generated HTML for post-processing? My editor.init code is shown below.
Thanks
Eric


public void init(Map<String, Object> params) {
        super.init(params);
        
        TablePrintFormAction action = new TablePrintFormAction("Visit Report", patientVisitsTable);
        patientVisitsTable.addAction(action);
        btnReport.setAction(action);
    }

Just to clarify a bit… the reason I want to post-process is so I can format some many-to-many references. Specifically, the Visit entity has a many-to-many attribute that I want to output as a comma-delimited list. For example,

Fruit: apple, pear, banana

I don’t know how to format in this way using the reporting module, so I thought I might use reporting to output the rest of the attributes and then add the MTM printouts using my own code.

Is there a better way to do this?
Eric

Hi Eric,

I think the best way to format many-to-many reference is using the groovy band in the report. You can format many-to-many attributes in the groovy script.
See Report Data Structure - CUBA Platform. Report Generator

I’ll look into that. Here’s what I came up with. The plan here would be to insert the MTMs after Cuba has done the rest of the formatting…


public void onReportB(Component source) {

        Map<String,Object> params = new HashMap<>();
        params.put("entity", patientVisitsTable.getSingleSelected());

        LoadContext<Report> lContext = new LoadContext<>(Report.class);
        lContext.setQueryString("select r from report$Report r where r.name like 'Visit Report'");
        List<Report> reports = dataService.loadList(lContext);
        Report report = reports.get(0);

        ReportOutputDocument outDoc = reportGuiManager.getReportResult(report, params, null);

        byte[] byteArr = outDoc.getContent();
        
        // Plan to insert formatted (comma-delimited list) MTM references into byte stream here
        
        ExportFormat exportFormat = ReportPrintHelper.getExportFormat(outDoc.getReportOutputType());
        ExportDisplay exportDisplay = AppConfig.createExportDisplay(this);
        String documentName = outDoc.getDocumentName();
        exportDisplay.show(new ByteArrayDataProvider(byteArr), documentName, exportFormat);
    }