JasperReports: Repeating subreport for each value of the list parameter - jasper-reports

I need to develop a report in JasperReports which contains ONE sub-report but the sub-report is repeated for every value in the list parameter.for example :
Parameter List to be passed to ONE subreport : 1,2,3,4
MyReport :
Subreport(Crosstable+ page break) for value 1 of the passed parameter
Subreport(Crosstable+ page break) for value 2 of the passed parameter
Subreport(Crosstable+ page break) for value 3 of the passed parameter
Subreport(Crosstable+ page break) for value 4 of the passed parameter**
Then the Subreport will also contain another "sub-Subreport" that should be repated X time for each value, example :
Subreport(Crosstable+ page break) for value 1 of the passed parameter :
"sub-subreport"(another Crosstable) for value 1.1
"sub-subreport"(another Crosstable) for value 1.2
"sub-subreport"(another Crosstable) for value 1.3
In other words i'm trying to loop on the same subreport but with different data something like :
for(i=0; i<list.lenght();i++){
print(subreport(i));
}
I don't to know how it can be done. I hope my examples are clear. Thanks in advance

Your detail band will fire for each record. So, if your input control is $P{myCustomers} and your main report's query is:
SELECT customer_id
FROM customers
WHERE $X{IN, customer_id, myCustomers}
Then your main report will have one field, $F{customer_id}. Your subreport needs to have a parameter of its own and it will get a value from the main report. Insert your subreport into the detail band of the main report. Click on the subreport from within the main report, and then in the Properties window of the main report, click on Parameters. The "Name" column is the name of the parameter in the subreport that will accept the incoming value, and the "Expression" field is the value to pass. So if your subreport also has a parameter for customer id, the name is customer_id and the expression to pass is $F{customer_id}.
The iReport documentation (http://community.jaspersoft.com/documentation/ireport-ultimate-guide) has information about subreports on page 90.

Try using report groups: the group is based on a value or on expression then you can embed subreport into the group.

Related

Crystal Reports SubReport parameter has multiple values

I have a report where I have created a subreport that uses a parameter from the main report but that value in the main report returns multiple of the parameter. Is there a way to specify in the parameter to only pull a distinct value into the parameter?
You could write a Formula to filter out the parameters you don't want, then pass that entire Formula as a parameter to the subreport.

How to show the result of a subreport only when a column value in the master report changes

I want to show the result of a subreport only when a column value in the master report changes
In the picture above first two rows have same values (Test) for "Name" column.
in the third row "Name" column have FEDEX value so Name column value changing
here I want to show subreport result. similarly when "Name" column value changes from FEDEX to UPS again subreport result should be shown.
In the report designer, you can add a group. The group by expression should be the $F{Name} field. Then, if needed, you can add a group header and / or a group footer.
Everything should be in place with this. Also, you should check the comment from AlexK on your other question: Did you read about Data Grouping?

Pass field value from dataset to subreport

I have a main report which retrieves some fields from DB. Under the main report, I have created a dataset which pulls one more field value say X from a different table. Now I have a subreport included on this main report. Is it possible to pass field X to the subreport?
Structure:
Main Report
--Dataset1 (retrieves field X)
--Subreport
Note: The field X is basically the average value which I need to pass to subreport which is printed several times based upon the number of results returned by the Main report query.
I am using Jaspersoft Studio ver 5.6.0
If not possible, what is the other option to pass this average value field to the subreport
I don't think it is possible, so another option will be use another subreport that gets the average. 1stSubreport(that will be in the Main Report) gets the average of the values and then it will have a FinalSubreport, which will get the average value along with anything else it needs
Main Report
--Subreport except Dataset(average field of X)
--Subreport that retrieves that number
If the final Subreport needs also fields from Main Report. Then Pass those values from the Main to the 1stSubReport to the Final Subreport

How can I pass parent's column value as parameter to child report in SSRS?

I have created master/details report from SSRS. Is it possible to pass as a parameter from parent's column value to child report. For e.g.
If I have a master report A and detail report B. From the following picture, how can I pass value of col_1 of Master_Report_A as a parameter for Details_Report_A
Any input will be appreciated.

How to pass variable's value from subreport to main report and show/hide detail band on the basis of that value in iReportDesigner Jasper Reports?

I am storing Value of one field in a variable in subreport. This variable I am returning to Main report. On the basis of this value I want to show/hide detail band 2. But I am not able to implement this as the value returned by the subreport is always Null which is a shock to me as when I am displaying the same value in subreport itself it is giving me 2 (integer). Please help me out with this.
For the First part of your question
The value returned by the subreport is always Null
In your Main report please cross check the following things.
You return variables from your sub report as in specified in here.
If the subreport and the text field in which you're using the returned value are placed on the same band, you need to set evaluationTime="Band" for the text field.
For the later part of your question,
I want to show/hide detail band 2
Using the report inspector, select detail band 2.
Access the properties of the band, using the properties tab.
You can find the property PrintWhenExpression.
Edit its value to hide/display detail band 2.
The second part of the answer works on the following logic
PrintWhenExpression will be evaluated at the start of the band rendering process, before starting to render the elements.
So, if the sub-report too is in the same band, detail band 2 in your case, this method would not hold good.