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

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.

Related

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);

All value parameter in postgresql

I have built a function to query data. I currently want to add another parameter to my function.
When the parameter is "ALL" it should display all data, else only the data that was queried.
if (p_agent = 'ALL') then
The above is what I have so far, I'm not sure what to do next to specify the ELSE statement. I am dealing with varchar/strings for that parameter.
the parameter is linked to this column:
bor.also_known_as
Link to CODE:
http://pastebin.com/h16BByfj
Thanks in advance

Default Value Expression for Optional String Input iReport

I'm using PostgreSQL as DBMS, in my current report I need an optional String parameter to get records by Id, which is a String field.
So I set the Default Value Expression to:
($P{Param} == null || $P{Param}.equals("")) ? "" : "AND id='" + $P{Param} + "'"
When the field is empty the report is created without issues, but when I enter a valid Id the compiler complains:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "160E0"   Position: 3126
Just like if I was adding double quotes after and before the value I'm passing. Somebody know how to handle this problem when using String values?
I guess, you've created one Parameter, named Param and in your query you have $P!{Param}. Thing is, default value is set only when parameter stays NULL after prompting, so when you input your ID, ${Param} value is passed into query as it was inputed by user (without AND id=' part).
Try creating second parameter, lets name it $P{input}; set its default value to your expression, "Use as a prompt" value to false. Pass it to your query ($P!{input}). Now, you have your ${Param} for prompting and when it's value is set to the desired ID, $P{input} is set to your query condition.

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.

I need the details section to suppress if a custom date field is blank in Crystal Reports

I have the following suppression formula in the details section:
{JCJM.udRough} <= #1/1/2013 12:00#
AND
{JCJM.udTrim} <= #1/1/2013 12:00#
and it works. However, I also need it to suppress if the udRough or udTrim field is blank. When I try to add
OR {JCJM.udRough}=""
it says that a date-time is expected where the blank quotes are.
Can someone please help?
As a general rule in CR, if a field can be null then you should explicitly check for that case first in a formula, otherwise it will not evaluate properly. Otherwise, CR will treat it like an unhandled exception.
So in your case, CR is short-circuit evaluating the expression {JCJM.udRough}<=#1/1/2013 12:00# as the very first thing, sees that the field is null, and stops evaluating the rest of the formula since it has encountered an exception.
What you need is:
(isnull({JCJM.udRough}) or {JCJM.udRough} <= #1/1/2013 12:00#)
and (isnull({JCJM.udTrim}) or {JCJM.udTrim} <= #1/1/2013 12:00#)
Try
if ISNULL({JCJM.udRough})
Then true
else false
This is from my understanding from your question if you are searching for something different let me know will try to answer it.