Check a field for a value
Check whether a field contains a value, is empty, or is null and act accordingly.
For this example, the data source includes the field orderline.order.contact
,
and the field is a STRING
. The field either contains a value, is an empty string,
or is null.
orderline.order.contact.trim().length()>0
This expression will
evaluate to either TRUE or FALSE.orderline.order.contact.trim().length()==0
orderline.order.contact.isEmpty()==TRUE
orderline.order.contact.isNull()==TRUE
Use in the Visibility Condition property
Expressions that evaluate to TRUE or FALSE can be used in the Visibility
Condition (visibilityCondition
) property. If the expression evaluates
as TRUE, then the instance of the element will appear in the report. If the expression evaluates as
FALSE, the instance of the element (to include all its children, i.e. the entire element tree) is
removed from the report. If you are using relative positioning, all sibling elements after this
element in the report structure shift accordingly, reclaiming the space that the element would have
occupied.
Use in the Text property
text
) property. The text property specifies the text to be
drawn.
orderline.orders.contact.trim().length()>0?orderline.orders.contact:""
In this
expression, the expression evaluates to TRUE when the length of the trimmed field is greater than
zero and the field value is printed (to include any leading or trailing spaces). If the length is
not greater than zero, the field is identified as not having a value and an empty string is printed;
the vertical allocated space for that field remains in the report.orderline.orders.contact.trim()
CHAR(N)
), you typically need to add .trim()
or
.trimRight()
to remove trailing spaces. You can avoid this by using the
STRING
data type. With the STRING
data type, the value is not
padded with trailing spaces unless trailing spaces are explicitly
set.DEFINE field1 CHAR(5),
DEFINE field2, field3 STRING
LET field1="ABC" -- you end up with "ABC "
LET field2="ABC" -- you end up with "ABC"
LET field3="ABC " -- you end up with "ABC ", as explicitly specified