Jump to content

Return field value from dataset to main report


nileshravinaik
Go to solution Solved by ecanaveras,

Recommended Posts

I need to hide a element on the main report based upon a field (say X) defined in the new dataset created on the main report. But the problem is, I cannot hide this element as this field X is not appearing under print when expression. Only fields identified on the main report query are showing up here.

So how do I hide this element now? 

Note, I cannot add the query from the dataset (which retrives this field X) to the main report query as that query already returns some other data from the DB.

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 years later...

I have found this solution at stack over flow  and this is the link :

https://stackoverflow.com/questions/10394401/how-to-return-value-from-tables-datasource-to-main-report-in-ireport

If you want to get some data from the table dataset, you actually can do this. I found a dirty trick to achieve this.

  1. Create VARIABLE variableMapName of type java.util.Map in main report and initialize it with expression new java.util.HashMap()

  2. Create PARAMETER parameterMapName of type java.util.Map within table dataset

  3. 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)

  4. 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!

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...