5
votes

I have a main Report in jaspersoft. Inside the main Report I have used two SubReports. Inside one of the subreport i have a variable Total Cash. I have to use this variable Total Cash in my next subReport. Is it possible to pass a variable from one SubReport to another SubReport. If not then how can i pass the variable from the SubReport to the main Report.

Thanks.

2
I have found this excellent explanation here: community.jaspersoft.com/questions/538582/…dellasavia

2 Answers

1
votes

You can get a return value from a sub-report to the main-report using the returnValue element. The following code sets the $V{result} value in the main-report to the value of $V{total} in the sub-report. This is much more obvious in iReport instead of jrxml code. Take a look at Subreports for more information.

<subreport isUsingCache="true">
  <reportElement x="18" y="11" width="189" height="77" key="subreport-1" />
  <connectionExpression>
    <![CDATA[$P{REPORT_CONNECTION}]]>
</connectionExpression>
  <returnValue subreportVariable="total" toVariable="result" />
  <subreportExpression class="java.lang.String">
    <![CDATA["C:/Program Files/JasperSoft/iReport-3.0.0/compile/Untitled_report_2.jasper"]]>
</subreportExpression>
</subreport>
0
votes

Absolutely you can :

Just set the return value from the first subreport to your desired variable in main report, then on your second subreport pass parameter with the value of your previous variable. But you will get null value if you placed second subreport in a same details band with the first subreport, then try to add more details band and place your second subreport here.