I have a table in my iReport which naturally has its dataset and I have a variable, that is defined and initialized in the table's dataset return a value (which definitely does within scope of table, not outside it) which I want to use in my main report which holds the table.
How can I do that or any alternatives?
If you want to get some data from the table dataset, you actually can do this. I found a dirty trick to achieve this.
Create VARIABLE variableMapName
of type java.util.Map
in main report and initialize it with expression new java.util.HashMap()
Create PARAMETER parameterMapName
of type java.util.Map
within table dataset
Link dataset PARAMETER with variable from main report using "Edit table datasource -> Parameters -> Add -> $P{parameterMapName} = $V{variableMapName}" (right click on the table in main report template)
Create variable putResult
of type java.lang.String
in table datasource. Expression for this variable will looks like this
$P{parameterMapName}.put("KEY", $F{fieldYouWantReturn}) + $P{parameterMapName}.put("KEY2", $F{otherFieldYouWantReturn})
Now you have an ability to use the data from table datasource in main report by using $V{variableMapName}.get("KEY")
It is really a dirty hack, but sometimes you have no other way to do something. Thanks!