4

I am newbie and I'm designing my report using iReport 4.5.

I have a main report (MainReport) and three subreports (Sub1, Sub2, Sub3)

In Sub1 I have three summary variables say presentPayable, presentPayment, balance

In Sub2 I have one summary variable say totalCost

I need to use the summary variables of Sub1, Sub2 in my Sub3.

How can I do this? Is this possible to pass the variables from one subreport to another?

Otherwise please provide me any alternate to do this.

Alex K
  • 22,315
  • 19
  • 108
  • 236
skaithepalli
  • 41
  • 1
  • 5
  • Possible duplicate: [Passing parameters from main report to subreport to subreport in Jasper](http://stackoverflow.com/q/13843167/876298) & [Pass subreport variable to other subreport](http://stackoverflow.com/q/7823179/876298) – Alex K Jul 04 '13 at 09:30
  • Hi Alex,I need to pass the parameters from one subreport to another subreport.I have not found the solution for this in the provided links. – skaithepalli Jul 04 '13 at 13:45

1 Answers1

2

To pass a value from a subreport to its parent, the parent must first have a variable to receive the value. In your case the main report should have 4 variables, one each for presentPayable, presentPayment, balance, and totalCost.

Next you need to add a returnValue element to the subreport element in the main report. This element maps a variable in the subreport to a variable in this report using the attributes subreportVariable and toVariable.

To do this in iReport, click on your subreport element in the main report. In the properties list, click on Return Values. A dialog should appear. Click on the Add button. Type the name of the subreport variable and select the variable in this report that you would like it to be transferred to. You should leave the calculation type as "Nothing", which will instruct jasper to simply overwrite the variable with the new value. Click Ok to add this, then repeat for the other variables/subreports.

Now when you run the report, each time the subreport has completed processing, the current value of the variable in the subreport is passed back to the specified variable in the main report.

To use that value in another subreport, you need to pass the variable from the main report to the other subreport as a parameter. This has two parts: Adding a subreportParameter to the subreport element in the parent report, and adding a parameter to the subreport itself.

In iReport, click on your subreport element in the main report. In the properties list, click on Parameters. In the dialog that appears, click the Add button. Give the parameter a name (e.g. presentPayable) and input a value expression that references the variable in your main report (e.g. $V{presentPayable}). Repeat this for each of the variables that you want to pass in.

Next, open your subreport. In the report inspector, right-click on Parameters. Select Add Parameter, then rename the new parameter to match the name you entered in the previous step.

In the subreport, you should now be able to reference these values like any other parameter (e.g. $P{presentPayable}).

GenericJon
  • 8,746
  • 4
  • 39
  • 50
  • Hi GenericJon,Thank You very much for giving the answer.I am done all the steps you mentioned except the last point.That is To use that value in another subreport, simply pass the variable from the main report to the other subreport as a parameter. Can you explain me this step by step.Bcoz i am not getting how to pass the variable as a parameter from one report to another report. – skaithepalli Jul 05 '13 at 05:11
  • @NSS: I've added some steps on how to pass it as a parameter. Hope that helps. – GenericJon Jul 05 '13 at 16:14
  • Not sure if i need to open a new question; lmk. I followed steps. My issue same i think. I need Volume1 per Entity for Date1 from Table1, Vol2 for Date2 from Table2, and [Vol2-Vol1] per Entity in Table3. //I fed Entity, Vol1 and Vol2 from first two tables to MainReport, then into Table3. ///However, when i preview, i get this error: Caused by: net.sf.jasperreports.engine.JRException: Variable WellID_Return is not assignable from source variable WellID. at net.sf.jasperreports.engine.fill.AbstractVariableReturnValueSourceContext.check(AbstractVariableReturnValueSourceContext.java:77) – dharol Aug 21 '17 at 22:50