Parameter passed to subreport always null when expression uses variable value

I have this master report that passes 2 parameter to a subreport. One of the parameters is the value of a field ($F{foo}), and it's ok. The other parameter has the expression $V{bar}. So, it's the value of a variable. This one is always null at the subreport although it's non null and printable in the main report in the same band where I put the subreport.

For the variable to be printable in the main report I have to use "evaluation time = band". If I use "Now" it's always null.

So basically I'm passing this null expression to the subreport because I can't tell jasper that the expression should be evaluated at the end of the band, as I do with a text field.

Any ideas on how can I pass a parameter to a subreport when the expression is the evaluation of a variable? Or how can I control the evaluation time of the expression of the passed parameter?

gustavofarias's picture
Joined: May 22 2012 - 7:10am
Last seen: 2 weeks 4 days ago

2 Answers:

As far as I know, evaluation time is not expected with the subreport. For example, when we print page no x of y, we call the same variable but x evaluation time now & y evaluation time report, which means the last result will print. 
Now If we pass this page no to the subreport it always takes current data means evaluation time now data. If the subreport print on the first page it will print 1 if it calls on 2nd page it will print 2. 
I attached a report I think will help you. where I pass the field and calculative variable to the sub-report.
The output will look like this. 

Package icon gustavofarias_issues.zip7.14 KB
mahadiosb's picture
Joined: Jan 24 2020 - 6:53am
Last seen: 2 months 4 weeks ago

There is a detail I didn't mention. The variable that I use in the expression of the parameter passed to the subreport is itself returned by another subreport. Later I saw in the docs that in these cases, the master variable that stores the subreport variable should be marked as "calculation=System". The lack of this setting was responsible for the variable being null most of the time. After I set it to "System" it took a value in the title band and kept it to the end, solving the original problem. Anyway, thanks for the explanation (with proof). I think this is the expected behavior. I mean, the passing of a variable to a subreport should evaluate when the report is being processed.

gustavofarias's picture
Joined: May 22 2012 - 7:10am
Last seen: 2 weeks 4 days ago