How to pass variable's value from subreport to main report and show/hide detail band on the basis of that value in iReportDesigner Jasper Reports?

Ayush Bilala picture Ayush Bilala · Dec 18, 2012 · Viewed 7.3k times · Source

I am storing Value of one field in a variable in subreport. This variable I am returning to Main report. On the basis of this value I want to show/hide detail band 2. But I am not able to implement this as the value returned by the subreport is always Null which is a shock to me as when I am displaying the same value in subreport itself it is giving me 2 (integer). Please help me out with this.

Answer

Gopinagh.R picture Gopinagh.R · Dec 18, 2012

For the First part of your question

The value returned by the subreport is always Null

In your Main report please cross check the following things.

  • You return variables from your sub report as in specified in here.

  • If the subreport and the text field in which you're using the returned value are placed on the same band, you need to set evaluationTime="Band" for the text field.

For the later part of your question,

I want to show/hide detail band 2

  • Using the report inspector, select detail band 2.
  • Access the properties of the band, using the properties tab.
  • You can find the property PrintWhenExpression.
  • Edit its value to hide/display detail band 2.

The second part of the answer works on the following logic

PrintWhenExpression will be evaluated at the start of the band rendering process, before starting to render the elements.

So, if the sub-report too is in the same band, detail band 2 in your case, this method would not hold good.