Jump to content
We've recently updated our Privacy Statement, available here ×

Pass a value to a subreport


asder99

Recommended Posts

 Hi!

Probably this is a stupid question, but I can't find a solution...

I'm trying to create a subreport, but I can't pass anything to it.

 

 

 

If I launch the subreport passing manually the id I need, it works perfectly.

But if I launch the main report, in the space where should be the subreport, is blank.

 

In the subreport's query, as an old manual says, I create a new parameters with the same name of the variable I need from the main report... but it doesn't work.

 

Probably I've got some problem because I use the last version of Ireport, the 3.7.6.

Anyone knows a step by step manual for create subreport with my version of ireport?

 

Thank you!

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 I've just understood where is the problem

I found this guide:

 http://jasperreports.sourceforge.net/sample.reference/subreport/index.html

And I've noteced that in my master report miss that part:

 

                

I write it in manually and now it works as it should do.
Anyway I don't understand how to set the subreport parameter automatically when I create a new subreport...



Post Edited by asder99 at 12/16/2010 09:41

Link to comment
Share on other sites

In your main report, select the subreport in question and scroll down to the bottom of the "Properties" pane.  You'll see "Parameters" and "Return Values".  You click on the little "..." button to the right to open the dialog for either of those.  To pass values from a main report to a subreport, click on "Parameters", and use the "Add" button in that dialog to add a new parameter.  The "Subreport parameter name" gets filled in with the parameter name in the subreport...you don't need the $P{} around the name...iReport assumes what you enter is a parameter name in the subreport.  In the "Value expression" you put an expression that should be passed to the subreport.  It could be a literal, a variable, an input parameter from the main report, a calculation, etc.

If you need to RETURN a value from a subreport to the main report, you define a variable in the main report to return the value to--make sure the data type is the same as the variable in the subreport that you'll be returning.  Define the Calculation for this variable as "System" if you're just trying to get the value itself back rather than the sum, average, etc. of multiple values returned over the course of the report.  Then click on the subreporty and in the Properties pane open the "Return Values" dialog and click "Add".  You enter the name of the Subreport Variable (again, no $P{} required) and the "Destination Variable", which means the name of the variable in your main report (no $P{}).  The value you return MUST be in a variable in the subreport...the subreport doesn't define an "expression" to return.

Hope that helps!  It seems like there are more questions about how to get a basic subreport working with parameter passing and with deploying to the repository than any other single topic!

Carl

Link to comment
Share on other sites

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