2005 IR Help Posted August 22, 2006 Share Posted August 22, 2006 By: Rotem Ben-Israel - rotemben pass grouping field as parameter??? 2004-02-04 10:55 Hello all, Can i pass the grouping field as parameter? example: i want to be able to group by country or state. i prepare the group, and give it a value of $P{GroupingField} then pass this to the report as a parameter. i'v tried, the parameter passed, but there was no grouping?? maybe it groups before it reads the parameters? if this is not possible, then another idea can be to pre-change the xml, compile it and run it. in this case, what is the best way to manipulate the xml? tnx in advance! Rotem By: Tobias Gaekle - ike987 RE: pass grouping field as parameter??? 2004-02-05 01:27 before the query is executed, all parameters are filled. try to set your parameter in the query like this: ... GROUP BY $P!{GroupingField} By: Rotem Ben-Israel - rotemben RE: pass grouping field as parameter??? 2004-02-05 03:44 Hi, tnx for the answer. i was refering to the jasper report group, where i want the report to be grouped by a certain field, not only change the querystring. i'd appriciate any answer on that. tnx a lot! By: Tobias Gaekle - ike987 RE: pass grouping field as parameter??? 2004-02-05 04:45 a new group will only be created when the group expression changes. if you put the parameter into the group expression, the expression will never change because your parameter never changes once you supplied it to the report. the expression would have to return the value of the field, not the parameter. so you would have to define an expression that returns the matching field value, for example: $P{GroupField}.equals("fieldname1") ? $F{fieldname1} : NULL By: Teodor Danciu - teodord RE: pass grouping field as parameter??? 2004-02-14 12:47 Hi, First of all, if you want to group records by some field, as Tobias said, the records have to be sorted by that field already. If not, when grouping by the country, you get the group "France" not only once, but every time France follows some other country. So the records have to be ordered by country if you want the grouping to be consistent. Secondly, what you want to do is to be able to chose on of two possible groups: one that is based on the $F{state} field and the other that is based on the $F{country} field. The you could merge them into a single group that would be based on a composite expression like this: <groupExpression> $P{MyGroupField}.equals("state") ? $F{state} : $F{country} </groupExpression> If thing are more complicated the this and you need an even more complex group expression, then you could always put the code in some method in one of you application classes and simply call it in the group expression. This way you'll have full control over the way your group breaks. I hope this helps. Teodor 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