Search code examples
jasper-reportsjasperserver

Jasper Server: passing argument to get report data for customer


I have almost the problem described here: iReport: Passing parameters from a main report query to a dataset query for a table or list

but since it's a few years old, I'm using iReports 5.1 with the newest comnunity version of Jasper Server.

I am able to fetch reports by PHP from the server, but I want to pass a parameter to the report to only display information for a distinct customer, having something like customerId in the database. So it only generates a report for a give customerId.

I don't want to create a single report for every customer.

How can I pass arguments to the datasource/main report, through the API?

Additional question: Is it possible to add this argument/parameter to scheduled reports?


Solution

  • Add to the report (XML):

    <parameter name="CUSTOMERID" isForPrompting="false" class="java.lang.String">
    </parameter>
    

    In the datasource (mongodb):

    {'collectionName':'test', findQuery : { customerId: $P{CUSTOMERID} }}
    

    passing the argument:

     ws_runReport($currentUri, $report_params,  $output_params, $attachments);
    

    Hope this will help someone else, too.