skaithepalli
skaithepalli

Reputation: 41

How to pass the parameter from one subreport to another subreport

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.

Upvotes: 4

Views: 4019

Answers (1)

GenericJon
GenericJon

Reputation: 8986

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

Upvotes: 2

Related Questions