How to pass parameters from a particular screen to report script?

Hi,
I want to implement report in a particular screen from where i need to pass the parameter and use that parameter in the script written for generating a report.

For example:
My script for generating a report is :


"select first_name from person where person_id = ${personid}"

I need to pass this personid from a screen as a parameter and use in the script.

Awaiting your response.
Bismay

Also a report could be launched programmatically using the ReportGuiManager.
In the following example:

  1. I have created the runReport method which is invoked by the reportButton .
  2. The report is printed by the reportGuiManager.printReport()
  3. The method receives report and a Map of report parameters
  4. Required reports are selected by query

public class DemoEntityEdit extends AbstractEditor<DemoEntity> {

    @Inject
    private Button reportButton;

    @Inject
    protected DataService dataService;

    protected ReportGuiManager reportGuiManager = AppBeans.get(ReportGuiManager.class);

    public void runReport(Component source) {

       Map<String,Object> reportParams = new HashMap<>();
        reportParams.put("entity", this.getItem());
        reportParams.put("additionalParam", "123");

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

        for (Report report : reports){
        reportGuiManager.printReport(report, reportParams);
        }
    }
}

Using that way note, that if the report has required parameter without a default value and it is not set from code, such report will fail to print.

1 Like

Hi,
If you need to run a report from the particular screen (entity browser or editor), and pass the selected entity to report as a parameter, it may be easily done as described in the documentation: [url=https://doc.cuba-platform.com/reporting-6.2/run_actions.html]https://doc.cuba-platform.com/reporting-6.2/run_actions.html[/url]

F.e. in my project I have the “DemoEntity”. I want to have a button on the “DemoEntity” edit screen, which prints the entity to report. This may be done by the following steps.

  1. At first, it is necessary to generate a report for an entity. The easiest way is to do it using wizard:
    open the Reports->Reports in menu
    click Create → Using wizard
    select the “DemoEntity” in the Entity field, press Next
    select columns for report, press Next
    select the report format and other options
    As a result an appropriate report is created. It has one parameter with type “Entity”.

  2. I also need a button to launch the report. Add it on screen using Studio.

   
...
        </fieldGroup>

        <button id="reportButton"></button>

        <frame id="windowActions"
               screen="editWindowActions"></frame>
 
  1. After that, I should adjust the action of the button to make it run the report.

public class DemoEntityEdit extends AbstractEditor<DemoEntity> {

    @Inject
    private Button reportButton;

    @Override
    public void init(Map<String, Object> params) {
        reportButton.setAction(new EditorPrintFormAction("Report for entity \"Demo Entity\"", this, null));

        super.init(params);
    }
}

“Report for entity "Demo Entity"” is the name of report, generated on the first step.

Thanks Rostislav. It worked for me.

Good example :slight_smile: