how should I set <PrintWhenExperssion> value true or false from java code - jasper-reports

I want to set
<printWhenExpression>![CDATA[Boolean.valueOf(true)]]</printWhenExpression>
to Boolean.valueOf(false) when I fill the report according to some conditions. This means I want to set value 'false' in <printWhenExpression> at run time. Can any one help me for this?

Instead of having hard coded value Boolean.valueOf(true)/Boolean.valueOf(false) use a variable which is evaluation to a boolean:
Boolean.valueOf(someVariableOfTypeBoolean)
or
Boolean.valueOf(someMethodThatReturnsBoolean())

Related

Crystal Reports - Only filter by parameter if it has a value, else return all values

How do you return all values if the parameter field is left blank? This is currently what I have in the selection expert:
if not(hasvalue({?parameter})) then true else {Table.Column} = {?parameter}
Set the 'Optional Prompt' property of the parameter to True:
Try this formula instead:
(not HasValue({?parameter}) OR {Table.Column} = {?parameter})
Using optional parameters in Select Expert formulas can be tricky. As soon as code is parsed that tries to say the parameter is equal to anything, it throws an error because the parameter has no value. The If...Then...Else logic still parses the entire block of code, regardless of whether the condition is true or false. In the formula above, if the parameter has no value in the first statement, the result is True, then the OR is parsed and the rest of the statement is ignored without parsing because it's result won't change the outcome of the formula.

How to set variable value after "Print when Expression" from textfield returned true

Using iReport I have a textfield with following "Print When Expression":
new Boolean($F{data}.doubleValue()<3 && $V{check}.intValue()==0);
My problem is that I only want to print this textfield once. For that I thought I can use a variable (check).
I tried to use this expression for the variable:
($F{data}.doubleValue()<3) ? 1 : 0
The problem is that the expression for the variable is called before the textfield checks its "print condition" and so the textfield never get printed.
How can I achieve that the variable value is set AFTER the textfield "print condition" returned true?
I want to mark the first value which is smaller than a reference value
I often use the parameter map (P{REPORT_PARAMETERS_MAP}) to store and evaluate custom expression depending on previous values and outputs
Example (return true if value $F{X}<100 and it has never been below before)
<printWhenExpression>
<![CDATA[$F{X}.doubleValue()<100?$P{REPORT_PARAMETERS_MAP}.put("X_LESS_100",true)==null?true:false:false]]>
</printWhenExpression>
This expression leverage the fact that Map.put(K,V) returns the previous value associated with key, that is null if never called, while second time $F{X} is below 100 it will return our previous set value that is true.
Note: you do not need to define any variable.
I found a workaround, but I don't find it a very good way, because my solution is related to the evaluation time of the conditions from the textfield and the variable.
So if anybody has a nice solution please post it.
I set the initial value of my check variable to 0.
The variable expression looks like this:
($F{data}.doubleValue() >= 3)? 0 : ($F{data}.doubleValue() < 3 && $V{check}.intValue()==0) ? 2 : 1;
The "Print When Expression" from the textfield is:
new Boolean($V{check}.intValue()==2);

Empty parameter in Crystal Reports Not showing NULL

I have a parameter that prompts the user to enter a value.
If that field is left blank I would think that the parameter would be NULL.
If I run:
isnull({?Param}) then
run this code...
The code does not run
BUT if I run it like:
hasvalue({?Param})
run this code...
The code runs!
Any idea why an empty param field does not return NULL?
From what I know,
hasvalue is used to check if a parameter has a value specified whereas IsNULL is mainly used in conjunction with a database field.
Which is why it may be behaving like that in your case.

Set a variable in iReport/Jaspersoft Studio

I have a report using many variables to calculate a rolling inventory over 16 months. The users are requesting some difficult calculations in the rollover amount (or carryover) such as only carryover amounts > 0, but only for some categories(groups), and then add the carryover from one category to the carryover in another category. I have most of the issues worked out, but I need to set a variable for the carryover ONLY when the group ="XXX", and maintain that variable value even when the group changes. I can easily set the variable to change over categories (groups) $F{group1}=="XXX"?QTY_ON_HAND - QTY_ORDERED:0.0, but when the group changes to "YYY" and then to "ZZZ" the value of the variable changes to 0. I need to use the value of the variable when it is in the "XXX" group as part of the calculation when it gets to group "ZZZ", but if it resets to 0 at that time, it is useless. I have also tried setting the variable = $V{rollover_amount} and have tried that changing the Calculation Type, Reset Type, and Increment Types to no avail.
I have the Calculation set to "No Calculation", Increment and Reset types set to "None"
I am using Jaspersoft Studio 5.5, but the same would apply to iReport Designer.
I see two potential approaches.
1) It looks like you've already started by creating the calculation by using conditional logic in the Variable Expression property. Continue with this approach. Try resetting the variable to itself when the group condition fails. Something like:
$F{group1} == "XXX" ? {do what you need to do} : $F{group1}
2) Use a JasperReport Scriptlet and manage the logic outside the report.
http://jasperreports.sourceforge.net/sample.reference/scriptlet/

iReport - Concatenating two variables with different evaluation time

I have two variables
$V{from} has evaluation value set to Now and
$V{to} has evaluation value set to Group.
Both seems to be working fine.
Now I need to append them. Currently I have $V{fromTo} which has expression $V{from} + "-" + $V{to}. Its evaluation time value is Group. What I want is just to simply append the current values of the two first mentioned variables. The current expression gives me the result (e.g. from = 1, to = 45)
45-45
Seems like the expression is taking the value of $V{from} evaluated during group execution time also. Any idea how to do this?
(Note, requirement does not allow me to just simply drag the two fields, i badly needed to store it in one variable)
I had the same problem. I solved setting Evaluation Time to Auto in my Text Field.