list of comma separated values

1

Hi experts,

I have a report where i am getting multiple account ids say 1 and 2 and  3 and 4 and  5

I need to pass all these account ids to a subreport as a parameter .

The subreport SQL will have a clause :- accountid in $p{accountid}

so in $p{accountid} i need a comma separated list of account ids.

but these accountids are returned rowwise(5 separate rows) in master report.

 

can you please tell me how can i prepare a comma seprated list of accountids to pass to my subreport.

 

Cheers,

Samrat.

 

so in $p(

 

 

chikida2007's picture
Joined: Mar 23 2011 - 2:14am
Last seen: 9 years 4 months ago

3 Answers:

1

Hi,

I'm not sure if this is what you are asking for but you could try to add the values to a variable. And then pass that variable to the subreport. This can be done by grouping the report (by country in my example):

Country               City

England              London

England              Cambridge

England              Oxford

Country Footer $V{City_List}

The Contry_List variable would be populated like this:

Variable Class: String

Calculation: Nothing

Reset Type: Group

Reset Group: Country

Increment Type: None

Variable Expression: see code below

Initial Value Expression: ""  (Make sure to set this to an empty String!)

 

 

 

 

 

Code:
"".equalsIgnoreCase($V{City_List}) ?
$F{city} == null ? $V{City_List}:$V{City_List}+""+$F{city}.trim():
$F{city} == null ? $V{City_List}:$V{City_List}.contains($F{city}.trim()) ? $V{City_List} : $V{City_List}+", "+$F{city}.trim()</td></tr></tbody></table>
phantastes's picture
Joined: Aug 22 2008 - 2:05pm
Last seen: 7 years 3 months ago

Hey @phantastes, I see the same code is not applicable for a BigDecimal field. What do I do in order to get a list of comma separated values for a field other than string, or in my case a BigDecimal?

yashaswita.bhoir - 7 years 1 month ago
0

Hi phantastes,

Thanks a lot for ur reply. I was also thinking in the same lines. But i didn't know how to implement it.

Can i have the values in the variable as comma separated strings such as :- '1000','1001','1002'

Also can you kindly explain me the variable expression code :-

"".equalsIgnoreCase($V{City_List}) ?
$F{city} == null ? $V{City_List}:$V{City_List}+""+$F{city}.trim():
$F{city} == null ? $V{City_List}:$V{City_List}.contains($F{city}.trim()) ? $V{City_List} : $V{City_List}+", "+$F{city}.trim()

A brief walkthrough will help me understand.

Thanks a lot in anticipation

 

Samrat.

 

 

chikida2007's picture
Joined: Mar 23 2011 - 2:14am
Last seen: 9 years 4 months ago
1

Hi,

Yes you can a string such as '1000','1001','1002' by just adding the single quotes to the exrpession below. I've added it to the code.

The expression adds the field value to the variable if the variable is not null. It also adds a comma before (and now a single quote before and after) the field. There is some extra checks to handle the first field being added to the variable (by not adding a comma before the first value).

I'm also adding the trim() method to make sure there is no blank space at the end of the string.

I hope that helps!
 

Magnus

Code:
"".equalsIgnoreCase($V{City_List}) ?
$F{city} == null ? $V{City_List}:$V{City_List}+"'"+$F{city}.trim()+"'":
$F{city} == null ? $V{City_List}:$V{City_List}.contains($F{city}.trim()) ? $V{City_List} : $V{City_List}+",'"+$F{city}.trim()"'"</td></tr></tbody></table>
phantastes's picture
Joined: Aug 22 2008 - 2:05pm
Last seen: 7 years 3 months ago
Feedback
randomness