Jump to content

Recommended Posts

Posted

Good afternoon. I would like to ask if Jasper supports list inside a list.
Here is an example:
image

In the first list i am using the invoice_id to fetch shipments that involved on this invoice but in the second list

that refers to shipment's cargo details, how can I write in the condition that the shipment_id is the one of the corresponding row?

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Posted

No Problem, I would advice using SubReports (no List-Elements !) for that purpose. Just pass the current primary key down to the SubReport as Parameter and use it for your SubQuery.

hth + regards

C-Box

Posted

Good morning dear, many thanks for your reply. 

 

The thing is that even with the subreport , i have to pass the primary key from the first list (a field), not a parameter from the main query,

 so for each row of the first list, a second list to be generated.

 

If this happens with a subreport, please give me further information on how to parse a field from the 1st list.

 
Posted

Well it's clear that you want to pass the current primary key from the field-value ...

So let's try to describe:

In your MAIN Report (jrxml) you have a SubReport1 (as Element)... at this SubReportElement you define a so called "SubReportParameter" with a name e.g. "TopMostPrimaryKey" and as parameter-expression you define the current field (e.g. $F{YourFieldForPrimaryKeyAtMainLevel} )

In your SubReport (jrxml) you then define a "normal" ReportParameter with the same name (e.g. "TopMostPrimaryKey") and the matching class type (Integer/String/whatever)

in your SubReport (jrxml) query you then can integrate this parameter in your where condition (e.g. WHERE SubTable.ParentKey = $P{TopMostPrimaryKey} )

That's actually all. :-)

So you will now just return the results from  the first Main record + the nested records  with the first primary key... then the SubReport returns and the next record from Main query will be called and the SubReport is also called with the second primary key... and so on....

 

now a bit clearer? 

hth + regards

C-Box

Posted

Hello dear,

indeed subreports seem to be the solution i am searching for, thank you for the instructions.

A quick question:

While the subreport file fetches data (given subtirid = 577 for example) (image1),

the main report show them as null (image 2).

Data Source Expression : new net.sf.jasperreports.engine.JREmptyDataSource()

I am parsing the field to the parameter as you can see on image 3.

 

Thank you in advance.

 

Posted

In your SubReportElement you just need to define the SubReportParameter by Name... so no $P{} logic is required there for the name of the SubReportParameter.

so just call it "subtirid" instead of "$P{subtirid}"

hth + regards

C-Box

Posted

Ok... so "SUBTIRID" it is on SubReportParameters... and what about the ReportParameter in the SubReport (the sub jrxml) itself? There it must have the SAME name (caseSensitive!) as in the parent SubReportParametersMap..... is this so? Otherwise you could perhaps attach your jrxmls

regards

C-Box

Posted

Hello C-Box! I managed to find what the problem is.

 

The connection expresion of the subreport must be the same as of the main report.$P{REPORT_CONNECTION}.

 

Thank you so much for your replies, your help is much appreciated.

 

 

 

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