Syntax is (condition) ? value1 : value2
In place of value1 and value2 you may have other constraints.
Here is an example that uses a Java constraint:
(($F{ca} > 8) && ($F{ca} < 12) ? "near 10" : (($F{name}.charAt(0) == 'A') ? "A": "Not A" ))
These are Java expressions, so you have to be careful with ==
and =
.
Now the print part...
So far you have defined a Variable variable1
, which is a String variable (could be anything else) and behaves accordingly to the constraint you have defined.
You just need to drag it from your the Variables group of your Report Inspector to the zone (most likely the Detail zone) of your report. Then it becomes $V{variable1}
and prints in your zone whatever the constrain dictates. That's it.
I found an approach that worked, similar to one of my ideas above. First of all, I could NOT get a subreport to return a value to the calling report, and then retrieve that value using getVariableValue from inside a scriptlet. I tried forever, and I just could not get that to work.
Instead, I went with the approach where I attached the same scriptlet to both the master and subreports. The scriptlet has a class variable where I can keep a running tally of all the product numbers I encounter in the detail, and this code goes inside the afterDetailEval() method of the scriptlet. Note that I only want this code to run for the subreport, so I do a check to see if a particular detail field, which will never be null, is present. If it's not, I don't run the code. So when that event is called by the master report, the code doesn't run.
Now for the part that I learned from the example. The admirable side-effect programming in the example is that there is a line of dimensions 1x1 that contains a call to a custom scriptlet method in the "Print When Expression" property. That's a great idea! So this custom method returns false no matter what, and the line never prints. I did the same thing in the Page Footer band, and this method collects the values from the class variable, determines the page, and stores the results in a hash. Then it resets the class variable.
In the Report Summary band, I have another line that will never print, that calls another custom method. All I do here is iterate through a map of product numbers and show all the pages each one appears on. Done!
Best Answer
I found the solution. Creating new group above all groups will solve the problem. In that group footer you enter things you want to see only on last page