Conditional blocks are sections of text that are inserted into a message based on a conditional statement. If the
condition is “true”, a particular section of text will be inserted into the message. If the condition is “false”, the text will not be inserted. An “ELSE” clause can be included as part of the conditional statement so that a different section of text will be inserted into the message when the condition is “false”.
Important: Conditional blocks use a significant amount of processing time. Use with care for jobs with a large volume of recipients. If messages will be substantially different for different recipients, then it may be more efficient (and easier to test) if the recipients are split up among multiple jobs with fewer conditional blocks, rather than trying to fit many different messages into one job with a complex conditional block structure.
The syntax of a conditional block is composed of directives and operators. A conditional block is coded by using the "
.BB" (begin block), the "
.EB" (end block), and the “
.ELSE" directives. Comments can be added without appearing in the final message by placing a “
.*” before the text containing the comment. Each directive must be on a line by itself, starting as the first character of the line. Conditional directives are not case sensitive.
A conditional block always starts with the .BB directive followed by a “condition” on the same line. The
.EB directive ends the conditional block. Fields used in a condition are preceded by an ampersand (“
&”), but are
not followed by a semicolon (“
;”).
The .ELSE command is used to execute the code in the block if the condition is false. Instead of not including any text if the condition is false, a different text can be included. For example,
if you wanted to add the recipient’s name to the salutation of a message so the greeting starts with “Dear fullname”, but not all of the recipient records have a name entered in the “fullname” field, then the use of a conditional block can ensure a salutation for all messages. Those recipients that have a name in the “fullname” field (condition is “true”) would receive a message with their name inserted, and those that do not have a name in the field (condition is “false”) can have a generic greeting inserted into the message instead.
Conditional blocks can be nested to any depth, creating opportunities to insert more than two pieces of text, depending on the conditions. For example, if the second condition is false, another variation of the text is inserted, and if the third condition is false, another variation of the text is inserted, and so on.
The condition that is evaluated is created by making a comparison against recipient data. Operator symbols make up the statement and appear in a table below. Operators are not case sensitive. However, == (strictly equal to) and ^== (not strictly equal to) are available when case must be respected. String literals within a statement must be enclosed within quotation marks if they contain spaces.
Boolean operators “AND” and “
OR” may be used within the statement.
If used, the sub-expressions must be enclosed within parentheses. For example, for this conditional block to be true both expressions must be met; the recipient must be in New York State and in New York City to see the text about winning sunglasses:
For the next conditional block to be true, only one of the expressions must be met; the recipient is either in New York State or in New York City. Recipients in “Albany, NY”, “New York, NY”, and “New York, CA” will see the text about winning sunglasses.
Any number of conditional blocks can be inserted into the body of a message. Conditional blocks will be processed and resolved by LISTSERV during delivery and will not appear as part of the final message that is sent to recipients. Figure 17-1 shows a plain text message that contains conditional blocks and merge-fields. Figures 17-2 and 17-3 show variations of the resulting message when certain conditions are met.
One of the most important steps to perform when using multiple conditional blocks is extensive testing. Send messages to test every condition and combination of conditions to ensure that your conditional text matches up with your recipient data in the expected manner.
However, if there are mistakes in the syntax of the conditional statement that turn up when the conditions are evaluated for each recipient, the test messages will
not be sent, although they will appear to, because LISTSERV cannot process the job with incorrect coding. No error message will be displayed in the Maestro User Interface. Errors of this nature will be reported in the LISTSERV logs and an email message will be sent to the LISTSERV Postmaster. If your test messages are not delivered in a reasonable amount of time, contact your LISTSERV administrator for assistance diagnosing the problem.
Presented in 17-1 is an example of a detailed plain text email message using mail-merge and complex conditional blocks. Each variable and combination of variables needs to be tested before the job is sent out. Some of the resulting test messages for particular combinations are presented in the following examples.