Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
report parameter not setting with 'setParameterValues'
walnash
I am trying to run a report in a servlet using IRunTask. I am setting the parameter of the report using setParameterValues(hashmap). My report has following types of parameters:
3 multiselect parameters and 3 simple parameters.
My hashmap is like this: HashMap<String, String[]> paramValues; This is taking value from a json like below:
"paramvalues":{
"param1":[
"value1"
],
"param2":[
"value2"
],
"param3":[
"value1",
"value2"
]
}
This is giving me an error saying the parameter which are simple are expected to be of 'string' and not java.lang.String. This problem is because the simple parameter is expecting just a string and not an array of string.
The problem now is that i want to set the report parameters all at once using a hashmap. But because of the above error i cant seem to set them all with a single hashmap. The only solution i can think of, is parsing my hashmap in to separate strings for each parameter. Is there any other way where i can do it using a single hashmap or set all the parameters in one shot??
Avinash
Find more posts tagged with
Comments
mwilliams
Can you attach a simple java class and a design that I can run that will show me what your setup is and what you're seeing? This way I can test on it. Thanks!
walnash
i have attached my java files. The RunAndMail class is called from a servlet which sends it a json as parameter which is of the type ReportEntity class.
I am using below json to test it:
{
"ReportEntity":{
"jobcode":"1",
"reportname":"MultiselectParameterQueryMod",
"paramvalues":{
"Status":[
"Shipped"
],
"parmorders":[
"339",
"487",
"486",
"484",
"151"
]
}
}
}
I have provided comments in my java class where i am getting the problem and i have also commented the code fix for this.
walnash
not able to attach the report file. So below is the XML of the report. Report name is MultiselectParameterQueryMod.
EDIT: Zipped example and original text into .txt file to shorten thread. (mwilliams)
mwilliams
In this particular report, this can be solved easily by choosing to allow multiple values in the parameter editor for the "Status" parameter. This causes it to expect a string array vs just a string. This may not work for your actual reports though. I'll let you know if I come up with a better solution.
mwilliams
Setting the single valued parameter to not be in a string array also worked, but this would just be doing the processing of the object before setting it to the report parameters rather than after like your commented out fix. It's looking like what you've got commented out might be the best way to do it.
walnash
Thanks Michael. The method 'setParameterValues' then, isn't serving much purpose at all. Not all reports can have all parameters as multiselect or single valued.
mwilliams
If you were to change your ReportEntity paramValues hash type to <String,Object>, you could pass the single values as just strings, instead of as string arrays and it works just fine. The issue in your case is that your hashmap is defined as a string array value and not all of your parameters are that.
walnash
Changing the paramValues hash type to <String,Object> also did not work. I am getting the below error:
The type of parameter "Status" is expected as "string", not "java.util.ArrayList".
I think this is because my JSON for key 'Status' is formatted as an array type:
"paramvalues":{
"Status":[
"Shipped"
],
"parmorders":[
"339"
]
I cant change this array type to anything else, as it will be difficult to know which parameter is simple and which is multi select in a report. Changing the hash type to <String,Object[]> works same as <String,String[]>.
Apart from this, there is one more issue. I thought that using the hash type as <String,Object[]> will help me attend to all data types of my report parameter. But this only works for String data type, even though the method setParameterValue() expects an object for parameter value. It is giving me the below error for other data types:
The type of parameter "CultureId" is expected as "integer", not "java.lang.String".
To fix this I had to parse each parameter to its expected data types which does not seem very elegant to me.
mwilliams
With your JSON object not being able to have a string type for single elements, you're probably stuck doing what you were doing at first. Though, it would seem that the same thing is done when you use your "commented out code", checking for a single value and assigning just that value to the parameter. I would think that when forming your JSON object, you could determine the same.