Design address labels

Design for a label that may contain three to five lines, depending on the data record.

Before you begin

Before reading this procedure, you should be familiar with designing a basic label report. See Design labels for more information.

About this task

A common label need is printing of address labels, yet the number of lines required for an address can vary, depending on the complexity of the address. In many database tables that store address data, there are several fields for storing address information, such as addr1, addr2, and so on. When creating an address record, those fields that are not needed for the new address are set to NULL.

When an address is printed out, however, those addresses that contain empty fields (addr2 is set to NULL, for example) can cause an issue. No blank line should appear on the label. In addition, we may have information that we want to print after the last non-blank address line included (such as a postal code).

Follow this procedure to answer these address issues.
Note: Field names used in this example have been simplified. Use the full field names as they exist in the Data View.
  1. Create your address label report.
    1. Use a Vertical Box (Layout Node) to contain all of the label data.
    2. Add all the lines of the address as children of this node, using dynamic layouting.
    At this point, you have designed a report that prints an address label. If one of the lines is empty, however, a blank line is printed.
  2. Identify which lines may contain empty values.
  3. For each line that may contain an empty value, set the visibilityCondition to specify that the line not print if the content is blank.
    For example, if one of the address label lines contains the data value shipaddr2, and this field has the potential of being empty, you could set the visibilityCondition as follows: shipaddr2.trim().length()>0
    With the visibilityCondition set properly, the line will not print if it has a length of zero. No blank lines appear within the address.
  4. If you have a set of lines where some may be blank, and you wish to print something at the end of the last non-blank line, you set this up using a conditionality expression in the value property. With this expression, you test to see whether any of the subsequent (or following) lines contains a value. If one or more of the lines contains a value, the current line is printed. If non of the subsequent lines contain a value, then the postcode is appended to the end of the current line and printed.
    For example, consider an address label containing three lines: addr1, addr2, and addr3. You have an additional field, postcode, that you wish to print after the last non-empty line.
    • For the line containing addr1, we test and see whether addr2 and addr3 are empty by setting the value as follows: addr3.trim().length()+addr2.trim().length()==0?addr1.trim()+postcode.trim():addr1.trim()
    • For the line containing addr2, we test and see whether addr3 is empty by setting the value as follows: addr3.trim().length()==0?addr2.trim()+postcode.trim():addr2.trim()
    • For addr3, it only prints if it is not empty (assuming the visibilityCondition is set correctly). Therefore, set the value as: addr3.trim()+postcode.trim()
    With the value property set properly, the last non-empty line will have the postcode at the end.