JasperReports: default value instead of 'null' - jasper-reports

Is there any way to set a default value to a field in a report? I have a lot of String fields in a report and would like them to display "0,00" when they're null.

Supposing the field name is "value", in the "Text Field Expression", write:
($F{value} != null) ? $F{value} : "0.00"

You can also select "Blank when null" in the properties of the text field if you want that. Other options are more flexible but this does the trick very quick and easy.

medopal's answer is good, but 2 additions:
1) You can make the syntax shorter:
($F{field_name}) ? $F{field_name} : "0.00"
2) Make sure your "else" data is of the same class as the field's value, otherwise you'll get errors when it tries to coerce numbers into string, etc. etc. This was something that, as I started out, I mixed up.

Did you try set a pattern in the text field?
If you are using iReport this can be found in the properties for the text field in the Text Field Properties section.
Try something along the lines of ###0.00 to represent 1234.56, which would always display 0.00 even if it is null.

This is the easiest way is to use Coalesce() or NVL() function of database in your data-source query to restrict null data on your report.
But it depends on if you are allowed to change the datasource query or not. If not then you can go for other solutions provided in previous answers.

Related

How do you return all matters where picklist option is null

Is is possible to return all matter records where a particular picklist value is null?
I tried the following:
https://app.clio.com/api/v4/matters.json?fields=id,display_number,client{name},description,practice_area{id, name},custom_field_values{id,field_type,field_name,value,custom_field,picklist_option}custom_field_ids[]=123456&custom_field_values[123456]=null
I also tried setting it to be blank. The api just returns an empty set.
Thanks for the help in advance.
Im not sure this is formatted correctly. The fields will be comma separated but then you did not include the & between the field and the custom_field_ids.

How to fulfill blank fields in Open Refine?

I found the blank rows, that is already great. Now I want to type "Not informed Value" to all blank values, but I don´t know how, Any hints.
Thanks in advance! I am having a great fun working with this distributed community!
Joni
Use "facet by blank-> true" to isolate the blank cells, then click "transform" on the same column and type the text you want between quotes.
It's also possible to perform the operation with a GREL formula (using "transform"):
if(isBlank(value.trim()), "Not informed Value", value)
Finally, since Open Refine 2.7, you can apply this kind of formula to each columns at once. Just click on "All -> Transform" and use the formula above.

Formatting a string in jaspersoft?

In my report I have a string field with some numeric value, for example 123102,6. I would like to display 123 102,60 in my report.
Formatting numbers is a bugger in Java in general but gets even trickier with Jasper.
If your report works with a Locale that provides the space as the number group separator (like, for example, Locale.FRANCE does), then all you need to do is specify #,##0.00 as the value of the Pattern property of your field.
If that is not the case, or you are using several Locales, or you are resolving them at runtime, then the simplest way to solve your problem is to provide this:
new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE))
.format(Double.valueOf($F{your_field_name}))
as the value of the Text Field Expression property of your field.

crystal - if statement - If field 'a' is blank then look at field 'b'

In Crystal 11, does the possibility exist to create a statement that would solve this issue I am faced with, using a formula field...
look at {fieldA} if there is a value listed, this should be the result
but if {fieldA} is blank then refer to {fieldB} then use this as the result
Any advice or example statements for me to look at would be greatly appreciated
Something like this:
if {fieldA} = "" then {fieldB}
else {fieldA}
Assuming you want to treat NULL values as blanks, then this is very straightforward. Simply create a formula field with this:
if {fieldA} > "" then {fieldA}
else {fieldB}
HOWEVER!! For this to work for NULL values of{fieldA} you MUST toggle to "Default Values for NULL option.

Jasper Reports: How to conditionally set the textbox style?

Is it possible in Jasper Reports to conditionally set a textbox style? If yes, how?
Please note that I'm aware of conditional styles, but I do not need a style which varies on a condition, but set the proper style using a different condition for each textbox (of course I could create a conditional style for each textbox, but that would be a real PITA...).
I'm using Jasper Reports 3.7.6 and the Jasper Studio Eclipse plugin.
Thanks
Use case example pseudocode:
bean1 {
f1
f2
}
bean2 {
cond1
cond2
}
<textbox1 style="(bean2.cond1 ? style1 : style2)">
bean1.f1
</textbox1>
<textbox2 style="(bean2.cond2 ? style1 : style2)">
bean1.f2
</textbox2>
Unfortunately you can't define a generic style. See page 135 of the iReport Ultimate Guide:
http://community.jaspersoft.com/documentation/ireport-ultimate-guide:
Please note that the conditions cannot be generic,
for instance, you cannot set a condition like “if the number is positive” or “if the string is
null
.” You must be very specific,
specifying, for example, that a
particular value (field, parameter, variable or
any expression involving them) must be positive
or
null, and so on.
Answering myself: it turns out that it is not possible to set conditional style the way I needed. I ended up with duplicating each text fields (a copy for each style), then setting the visibility upon the condition. Boring and time consuming, but it works.