How to schedule a report with collection type parameter via rest api in jasperserver?

 

Jasperserver v4.5

We are having difficulties with scheduling a report by using rest api. We are able to schedule a report that only accepts string parameters however the problem begins with a report that has a java.util.Collection type parameter. We tried everything but couldn't find the correct type for java.util.Collection.

Right now this works:

<parameters><pre style=""><parameters><div><parameters></parameters></div><div>    <name>string_input</name></div><div>    <value xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string"></value></div><div>        test</div><div>   </div><div> </div>
</parameters>

But we couldn't get this working:

<parameters>
 
    <name>array_parameter</name>
 
    <value type="?">[1, 2, 3]</value>
 
</parameters>

When I looked into the code, I can see that jasperserver ws accepts arrays, however there is no documented way to send the arrays or array types.

What is the correct way to solve this issue?

Thanks

berk.caputcu's picture
Joined: Dec 19 2012 - 11:35am
Last seen: 9 years 12 months ago
Have you found a solution for this topic? We have the same problem here. :/
ragn - 10 years 1 month ago

1 Answer:

We took a different approach. Instead of sending the parameter as array, we are sending the array as comma separated string to another parameter. And from iReport, we set the default value of the Collection parameter to get the value from this other parameter and parse it into an array. I know it's not the neatest solution, but it was the only way we could get it to work. Let me explain it with simple code samples.

array_parameter is the Collection type parameter we want to initialize. We tried it like this but it didn't work.

<parameters>
 
    <name>array_parameter</name>
 
    <value type="?">[1, 2, 3]</value>
 
</parameters>

That's why we took this approach:

This is the XML we send to the rest api. You should create a new parameter in your report with the name array_parameter_csv and make sure that the new parameter is at the top (or before the actual Collection parameter). --For the code below don't forget to initialize xsi and xs--

<parameters>
 
    <name>array_parameter_csv</name>
 
    <value  xsi:type="xs:string">1, 2, 3</value>
 
</parameters>

And then from iReport, set the Default Value Expression for the Collection parameter to:

new ArrayList(Arrays.asList($P{array_parameter_csv}.split("\\s*,\\s*")))

And it works...

berk.caputcu's picture
Joined: Dec 19 2012 - 11:35am
Last seen: 9 years 12 months ago

How to pass a single parameter through XML using rest_v2 (for scheduling report)?

jigar.patel - 8 years 2 months ago
Feedback