Multiple field in text field - jasper-reports

I have an XML documents which include 3 titles.
<page>
<title>
<title>
<title>
Now I want to show them in one text field. I do the following
$F(title)+","+$F(title2)+","+$F(title3)
and it works well. There is a problem if title2 and title3 will be empty. assume if title2 is empty in XML than the result is being like blow:I
This is the title 1 ,,This is title 3
is there suggestion for this?

Something like this should work:
($F{title} != null ? $F{title} : "" )
+ ($F{title2} != null ? ", " + $F{title2} : "")
+ ($F{title3} != null ? ", " + $F{title3} : "")
This is assumes that:
a) empty means null
b) field $F{title} will never be null
If I am wrong on assumption (b) this the expression gets only a little more complex. It can be done.

Related

npgsql : Selecting a null data throws exception with error "Column is Null"

I am running npgsql v3.7 with .NetCore on Ubuntu.
When I execute a select query and a cell in any row in the results is null, an exception is thrown with the error message "Column is null".
I am having to work around this by putting every column in the select clause inside a case statement which tests for NULL
"CASE WHEN " + fieldName + " IS NULL THEN '' ELSE " + fieldName + " END "
This seems a bit extreme and should not be necessary. Has anyone else come across this.
Thanks.
You are probably trying to read the column like this:
using (var reader = cmd.ExecuteReader()) {
reader.Next();
var o = reader.GetString(0); // Or any other of the Get methods on reader
...
}
This code will fail if the column contains a null, and is the expected behavior. In ADO.NET, you need to check for a null value with reader.IsDBNull(0) before actually getting the value. That's just how the database API works.
I don't know why NULL values are giving you errors, but you can do away with the ugly CASE statement in favor of using COALESCE:
"COALESCE(" + fieldName + ", '')"
Ideally you should make a configuration change such that NULL values do not cause this problem.

field value can't display in null condition in jasper report

I have problem when i'm using a condition for checking null values in report. My condition is
$F{BILANGAN4}==0 ? "-" : ""
The values of field does not appear but it just appear "-".
Anyone know about this?
I'm not sure what $F{BILANGAN4}==0 ? "-" : "" will compile-down to. Have you looked at the generated .java code for your report? java.lang.Long could be null, so you want to check like this:
( ( null == $F{BILANGAN4} || $F{BILANGAN4} == 0 ) ? "-" : "" )
I usually explicitly add .longValue() to calls like that just to be explicit: I'll get a compiler failure if the type isn't correct and I know I need to adjust something and maybe re-consider the code.
Note that the above code (as a text-field value for instance) will only display "-" or nothing. If you want the value of the $F to actually display, you'll have to put it in there. I'm fairly sure this is actually what you want:
( ( null == $F{BILANGAN4} || $F{BILANGAN4} == 0 ) ? "-" : $F{BILANGAN4} )

Birt Report Multiple Input Parameter

My problem are same with this question
here
I tried the solution at that question but it only work if all the parameter has value, but when there are no value the Birt Report output this error
The following items have errors:
Table (id = 4):
+ Can not load the report query: 4. Errors occurred when generating the report document for the report element with ID 4. (Element ID:4)
Can you guys help me?
Thanks
In that example when the parameter has no value the query is not modified from what you put in the query text box. You could also do something like:
1- put a query in like select * from mytable
2 - Then put a beforeOpen script like:
if( params["myparameterval"] ){
this.queryText = this.queryText + " where col1 = " + params["myparameterval"].value;
}else{
this.queryText = this.queryText + " where col1 = hardcodedvalue"
}

Report Builder .rdl Check Array Key Exists

I am making a report and I need to split a coma separated string into three columns of a table.
string = 'some text, some text, some text'
But the sting doesn't always have two coma's i.e.
string = 'some text, some text'
so when i try to get the value for the third column
=Split(Fields!GLDescription.Value, ", ").GetValue(2)
This code can result in a "#Error" message in the column. I tried to solve this by checking the length like so
=IIF(Split(Fields!GLDescription.Value, ", ").Length >= 3, Split(Fields!GLDescription.Value, ", ").GetValue(2), "")
But it still resulted in the same error. Is there anyway to check if an array key exists?
The issue, as you've seen, is that SSRS IIf expressions aren't good at short circuiting. I can think of a workaround that will work for 2 and 3 column fields.
Try an expression like:
=IIf(
Split(Fields!GLDescription.Value, ", ").Length = 3
, Mid(
Fields!GLDescription.Value
, InStrRev(Fields!GLDescription.Value, ", ") + 2
, Len(Fields!GLDescription.Value) - InStrRev(Fields!GLDescription.Value, ", ") + 2
)
, "No val 3"
)
With dataset:
Gives result:
It's not bulletproof for all possible situations, but might be enough for your data.

doing comparison if else in JasperReports

I want to do a comparison such as:
if <field> == 0 then "-"
Can somebody tell me the syntax using JasperReports?
iReport (JasperReports) uses a Ternary operator. For example, consider the following logic:
IF boolean condition THEN
execute true code
ELSE
execute false code
END IF
Using a ternary operator, this becomes:
boolean condition ? execute true code : execute false code
When using a variable with the following expression:
$F{column_value}.intValue() == 42 ? "Life, Universe, Everything" : "Naught"
Then the variable's value would be "Life, Universe, Everything" if, and only if, the integer value of $F{column_value} is equal to 42.
Where things get a little obtuse is when you have to have nested conditions. For these, put the nested conditions in parenthesis and on a separate line:
condition1 ?
(condition2 ? true_code2 : false_code2) :
false_code1
So when you need to do many of them:
condition1 ?
(condition2 ?
(condition3 ? true_code3 : false_code3) :
false_code2) :
(condition4 ? true_code4 : false_code4)
example of expression in ireport:
(
$F{foo} == 0 ?
"Planned" :
$F{foo} == 1 ?
"Reserved" :
$F{foo} == 2 ?
"Canceled" :
$F{foo} == 3 ?
"Absent" :
$F{foo} == 4 ?
"Complete" :
"Unknown"
)
Use if-else condition:
if customer name is null write '-' (absent), else write customer name.
Be careful of your field data type!
<textFieldExpression class="java.lang.String">
<![CDATA[
$F{CustomerName} == null ? '-' : $F{CustomerName}
]]>
</textFieldExpression>