ondreia Posted November 17, 2006 Share Posted November 17, 2006 Hi everybody How can I pass a field from my report to my subreport Example:I have a query in my report like:select a, b from table1; In my subreport i want to do :select c from table2 where test='a'. How can i do this???Thanks!!! Link to comment Share on other sites More sharing options...
rsilverns.sympatico.ca Posted November 17, 2006 Share Posted November 17, 2006 Create a subreport parameter (for the sub-report from the main report) called "paramA" and pass it the value you wish by setting the report expression as needed. If the value is in a field try using $F{myField} as the expression, if its a parameter that was passed to the main report, use $P{myParam} etc. etc. Then in the sub-report create a parameter called "paramA" which will receive this parameter. Link to comment Share on other sites More sharing options...
ondreia Posted November 17, 2006 Author Share Posted November 17, 2006 Thanks rsilver!!! It's a value in a field.I create (in my report) a parameter and i put in the default value expression: $F{mfield}. Then Im my subreport I create a parameter with the same name but it didn´t work :( Am i doing anything wrong?? Link to comment Share on other sites More sharing options...
ondreia Posted November 17, 2006 Author Share Posted November 17, 2006 IT's done!!!:) :) Thanks to everybody Link to comment Share on other sites More sharing options...
blckn Posted December 5, 2006 Share Posted December 5, 2006 Hi, can you please write your solution..i am experiencing the same problem, i have a parameter in my main report and would like to use it in the subreport too. So, in the subreport properties window, i have added all the parameters of the main report to the subreport. Then, in the subreport, i have created a parameter with the same name and properties and thought this paramter wold know take the passed value, but it is not! The report query of the subreport encounters an error as I try to use the parameter in the query and as the parameters value is null. So, if you could please write, how you have solved your problem, it would be very helpful for me.. thx in advance,blckn size=371]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/sub.JPG Link to comment Share on other sites More sharing options...
blckn Posted December 6, 2006 Share Posted December 6, 2006 how did u do that? I thought you can not assign the value of a field to a parameter, because the parameters are initialized before the fields. This is how we can use the parameters in queries. So how did u pass to field to a subreport? I need to use the field value in my subreports and could not find any solulcktion. Tried the solution above but it did not work..so now you have written that you found something and I kindly ask you to share it with us...Did you assigned the value of the field to a variable? If yes, how did you pass the variable to the subreport? Because using iReport only parameters can be passed tı subreports.. I really would appreciate if you could share your solution with us.. thx in advanceblckn Link to comment Share on other sites More sharing options...
rsilverns.sympatico.ca Posted December 7, 2006 Share Posted December 7, 2006 If your using the parameter in the report queryString, you may want to try adding a '!' to the paramater.. so $P{myparam} becomes $P!{myparam}. This sometimes helps, depending on usage. HTH,Robin Link to comment Share on other sites More sharing options...
caid235 Posted June 18, 2014 Share Posted June 18, 2014 Using iReport 5.2:In the master report, click on the subreport, and find Parameters in the Properties box. Click on the ... button to open up the Parameters dialog.Click Add and type in a name for the parameter. You will see a button on the right. Click it and you will see all the parameters, fields, and expressions from the master report. Select the field you want to use. Click OK twice to save all this.In the subreport, create a parameter with the same name as the one you just entered in the master report. Now use it like any other parameter,That's all there is to it. Link to comment Share on other sites More sharing options...
manish432 Posted September 11, 2014 Share Posted September 11, 2014 Thanks! @caid235 Its the simplest way to pass field to a subreport Link to comment Share on other sites More sharing options...
meulth Posted March 16, 2016 Share Posted March 16, 2016 The simplest and best way to pass field to a subreport Link to comment Share on other sites More sharing options...
just-passin-thru Posted October 11, 2017 Share Posted October 11, 2017 I'm trying to do exactly this now with jaspersoft studio 6.2 I have created the parameter based on a field from the main report. The report runs, when I display the data on the main report it prints but but is always blank on the table. I've spent literally hours on this reading just about every thread, but I couldn't find any clear direction that is current. Maybe its my data source settings (not mentioned here)? I've tried all sorts of variations from other threads, but always the textfield displaying the parameter in the table is empty. Is it not possible to pass a FIELD from main to a subreport or table? I've seen conflicting statements of differing age so I can't really tell what's true currently. I know I can just perform the query in the subreport. But I have a very efficient query in main so I see no reason to not just reuse the data. Why hit the db again when I've already pulled all the data I need. Thanks! UPDATE For anyone else that stumbles across this post, here's how I resolved it. Don't know why it didn't occur to me sooner, but you don't have to use the table component for this. You can simply place textfields and static textfields arranged to LOOK like a table in the main report using the main fields. It will still export to docx as a table that can be manipulated in word like any other table (that was one of the business requirements for the report I was working on). I also had to mesh a table with data from the main report together with several rows from a subquery. So I used the same technique for the main report data, then added a table component with just the detail rows and physically placed it under the static text 'table'. It also exported to docx properly. jaspersoft studio FTW! Link to comment Share on other sites More sharing options...
poojaprasad Posted February 21 Share Posted February 21 best way, thank you Using iReport 7.2: In the master report, click on the subreport, and find Parameters in the Properties box. Click on the ... button to open up the Parameters dialog. Click Add and type in a name for the parameter. You will see a button on the right. Click it and you will see all the parameters, fields, and expressions from the master report. Select the field you want to use. Click OK twice to save all this. In the subreport, create a parameter with the same name as the one you just entered in the master report. Now use it like any other parameter, That's all there is to it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now