Jump to content

Using variable set in a scriptlet as a group expre


pbrack

Recommended Posts

Hi All,

This is my first post to the form, apologies if it is a little newbieish....

The report I am writing at the moment takes a datasource contraining start and stop events for journeys that occurred during a given period. The report matches up the start and stop events to create journeys and calculates totals appropriately. I have achieved this functionality with a scriptlet up to this point.

I now want to group the result data by 'date', which sounds simple, surely I could just use $F{date} as a group expression? The problem is thus: 

Here is a simplified dataset

id type date
1 start 01/01/2009
2 stop 01/01/2009
3 start 02/01/2009

As jasper iterates over the dataset it matches these start/stop events up, once it has a valid pair it a boolean (hasJourney) is set to true. This variable is used as a print expression on the details band. This results in the print expression being evaulated as true on the 3rd row which means that using the simple group expression above would result in the row made up of row 1 and row 2 being grouped in the '02/01/09' group.

I then defined another variable, within the scriptlet, that stores the date of the row to be printed, I then tried to set the group expression to $P{CUSTOM_SCRIPTLET}.date. I have added trace into my scriptlet that shows that the date variable is being updated correctly, however, my report is returned with one group rather than many.

If anyone could shed some light on what I am doing wrong I would really appreciate it as I seem to be going round in circles.

Thanks,

P

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

 

Using scriptlet variables in group expressions does not work, because the group expressions are something special.

In order to detect a group break, the engine actually tries to make a step ahead and "estimates" the future value of the group expression, before actually triggering the group break.

When you handle the variable value yourself in the scriptlet, the engine has no way of "estimating" it.

 

You need to devise a way in which variables involved in group expression are not touched with the scriptlet, but are the results of variable expressions alone.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

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