action.skip

How to conditionally display address data on the PDF?

← PDF and Email FAQ

Your business may require to include certain data to address on the PDF on the condition that it is available. If the relevant field is empty, you want it to be left off completely, without even adding a blank line.

Assume the following example: You want to include the address line "For the attention of" if there is a relevant contact is available, but you do not want the line to be printed if there is none.

This requires

  • A custom formula field that produces the text to be displayed if there is an associated contact
  • An allowlist entry for the custom formula field
  • A custom placeholder for the formula field to included in the address field of your invoice template

Following the example, the configuration involves these steps:

  1. Create the custom formula field Attention (return type Text) on the Invoice object.

    Specify this formula:

    IF(ONB2__Contact__c != null,
        'Attn. ' + ONB2__Contact__r.Salutation + ' ' + ONB2__Contact__r.FirstName + ' ' + ONB2__Contact__r.LastName,
        null
    )
    

    This formula checks whether there is a contact. If so, it returns "Attn." together with the contact's salutation, first name and last name as a text string. Otherwise, it leaves the field blank.

    Make sure to select Treat blank fields as blanks.

    A localized variant of the formula – for Germany, for example – may look like:

    IF(ONB2__Contact__c != null,
        CASE(Text(ONB2__Contact__r.Salutation),'Mr.', 'Herrn', 'Frau') + ' ' + ONB2__Contact__r.FirstName + ' ' + ONB2__Contact__r.LastName,
        null
    )
    
  2. Allowlist the new formula field to make it accessible for custom placeholders.

    For details, see Field Whitelist.

  3. Create the custom placeholder [Attention], setting it up to retrieve the Attention field on the invoice.

    For details, see Custom Placeholders.

  4. Add the new placeholder to the address field of your invoice template.

    Make sure to include the placeholder filter linebreak. This inserts a line break if the field is set (that is, if the rendered text is not blank), and otherwise, if the field is empty, there will be no empty line.

    The recipient address field on your template may, consequently, specify the following placeholders (in one line):

    [AccountName|linebreak][Attention|linebreak][RecipientStreet|linebreak][RecipientPostalCode] [RecipientCity]
    

Related information:

Address Data
How to selectively display a field on the PDF?