Dynamically selecting report template

Hello Cuba team,

I know we can run run the report from the screen by setting the action to button as its there in many samplers. But how can we automatically select the template from the report screen?
I may have many templates for one report and I dont want to select the template every time from the parameter as it can be automatically selected based on the selected record need report.
Attached is the screenshot where I have 4 different templates for one report.

templatesrun

Thanks ,
Saurabh

Hi,

Just pass the template code as a parameter when running the report, see examples here and here.

Hi,

Sorry but what is this query string :

lContext.setQueryString("select r from report$Report r where r.id = '3ef3a9ed-0eb3-cc2a-be2b-7f175a25bab0' ");

in the above link you shared.

It’s just a way to load the required report instance using LoadContext. Actually, for passing the template, you need the printReport() method of ReportGuiManager.

Thank you very much, its working fine. But when I set any parameter in "parameter and format I am getting below error:

IllegalArgumentException: Required report parameter "underwriters" not found

See below is the parameter I set for.

report parameter

And this is the error I am getting:

nmfs

Hi,
If you have required parameters you must set them when launching the report.

Something like this:

     @Inject
     private Table<Customer> customersTable;
      ...

     public void runReport(Component source) {

            Map<String, Object> reportParams = new HashMap<>();
            reportParams.put("underwriters", customersTable.getSelected());
      ...

            reportGuiManager.printReport(report, reportParams, templateCode, null);
        }
1 Like

thank you @iskandarov . it worked perfectly

If the “underwriters” is a list of entities “multiselect” should be enabled for customersTable.
To avoid IllegalArgumentException you can check whether the records are selected before launching the report.

     @Inject
     private Table<Customer> customersTable;
      ...

     public void runReport(Component source) {

        if (customersTable.getSelected().isEmpty()){ // if no records are selected in the table
            showNotification("please select items");
            return;
        }

        Map<String, Object> reportParams = new HashMap<>();
        reportParams.put("underwriters", customersTable.getSelected());
      ...

        reportGuiManager.printReport(report, reportParams, templateCode, null);
    }