Felipe Reis
Felipe Reis

Reputation: 469

Jasper REST pass collection as parameter

I have a report which receives a List parameter to use it in a IN clause:

$X{IN, personID, _personID}

The report works when running it through the web application or remote repository view in iReport.

Now I need to call it using the REST api. I have tried several different ways of passing the list value in my resource descriptor but none of them worked.

<resourceDescriptor name="Test_Report" wsType="reportUnit" uriString="/Test/Test_Report" isNew="false">

    <parameter name="_personId" isListValue="true"><![CDATA[1]]></parameter>

</resourceDescriptor>

The above example returns the following error:

Invalid type java.lang.String for parameter _personId used in an IN clause; the value must be an array or a collection.

I have also try the following:

<parameter>
<name>_personId</name>
<value isListValue="true">
    3
</value>
</parameter>

But this returns a report with all the records, not only the person with Id=3.

Upvotes: 4

Views: 4011

Answers (2)

Onurus
Onurus

Reputation: 54

Your approach is totally fine, but there is also another small tip with collection type arguments ( might be a bug)

  • If you have more than 1 item in the collection this is totally working correctly: (3,4,5,6)->?_personId=3&_personId=4&_personId=5&_personId=6
  • If you have only 1 item in the collection you have to add empty one too: (3)->?_personId=3&_personId=

By the way, I am using Jasper Server CE 7.2.0 on the docker.

Upvotes: 1

Felipe Reis
Felipe Reis

Reputation: 469

My workaround for this problem was to use the REST V2 services of JasperServer.

Added to this the V2 has two advantages over the first version of the service:

  • it doesn't require a resource descriptor
  • it runs and exports the report in a single GET request

All the information required to run and export the report is passed through the request URL, for example:

<host>/rest_v2/reports/Test/TestReport.html?_personId=3&_personId=4&_personId=5&_personId=6

Upvotes: 4

Related Questions