Previous Topic

Book Contents

Book Index

Next Topic

Preventing Empty Values in the Email Body

It is possible to prevent empty spaces or empty lines being displayed if the corresponding attribute value is missing in the referenced business object.

Example use case:

  • A) An email template created for the Ticket object type is designed to contain a line displaying label 'System' and the name of system for which the ticket had been filed.

    Here we want to prevent displaying only the label followed by an empty space (no system name displayed). We also want to prevent a somewhat better scenario - an empty line (no label and no system name displayed).

    or

  • B) An email template created for the Ticket object type contains a table displaying in one of its cells the 'System' label and in the neighbouring cell the name of system for which the ticket had been filed.

    Here we want to prevent displaying one (system name) or two (system label and name) empty cells in the table.

Leaving out the empty values is achieved in the email template by replacing the actual label or attribute value with an indexed two-item field with the attribute value (e.g. name of the system) in position 0 and an empty string in position 1. Which of these two items is used in the email is determined by a condition expression which returns a '1' boolean value if the attribute value is empty or a '0' value if the attribute value exists. This the actual value must be in position 0 of the indexed field and the empty string must be in position 1.

Example use case solution:

Condition expression [not bo.system__systemname] will be used to determine which item of the indexed field will be displayed. IMPROTANT NOTE: two subsequent underscore characters are used between 'system' and 'systemname'.

  • A) If the label and the value are located in a single row, use the following syntax:

    <%("System: %s" % bo.system__systemname, "")[not bo.system__systemname]%>

  • B) If the label and the value are located in two separate table cells, use the following syntax:

    LABEL:

    <%("System:", "") [not bo.system__systemname]%>

    VALUE:

    <%(bo.system__systemname, "")[not bo.system__systemname]%>

Preventing an empty line in use case A)

Using the syntax in use case A above would still result in an empty line in the email. To prevent this, add a break tag to the non-empty item of the indexed field and directly after the whole expression continue with the text which should be displayed on the subsequent line of the email.

<%("System: %s<br>" % bo.system__systemname, "")[not bo.system__systemname]%>This is the text for the subsequent line

See Also

Email Body