action.skip

How to selectively display a field on the PDF?

← PDF and Email FAQ

Your business may require to print a field to the PDF on the condition that it is filled. If the field is empty, you want it to be left off the document.

Assume the following example: You generate invoices from opportunities. You want the Order Number of the opportunity to be displayed on the invoice PDF if the value is available, but you do not want the field to be printed if it is empty.

This requires

  • A custom formula field that produces the text to be displayed if there is a value available
  • An allowlist entry for the custom formula field
  • A custom placeholder for the formula field to be put on your invoice template

Following the example, the configuration involves these steps:

  1. Create the custom formula field Opportunity Order Number (return type Text) on the Invoice object.

    Specify this formula:

    IF(NOT(ISBLANK(Opportunity__r.OrderNumber__c)),
        'Opportunity Order Number: ' + Opportunity__r.OrderNumber__c,
        NULL
    )
    

    This formula checks whether there is an Order Number value for the opportunity. If so, it returns the specified label and the retrieved value as a text string. Otherwise, it leaves the field blank.

    Make sure to select Treat blank fields as blanks.

  2. Allowlist the new formula field to make it accessible for custom placeholders.

    For details, see Field Whitelist.

  3. Create the custom placeholder [OppOrderNo], setting it up to retrieve the Opportunity Order Number field on the invoice.

    For details, see Custom Placeholders.

  4. Add the new placeholder to your invoice template.

    Depending on the intended location of the field on the PDF copy, you may have to add an HTML line break (<br/>) at the end of the text to be produced by the formula, like

    IF(NOT(ISBLANK(Opportunity__r.OrderNumber__c)),
        'Opportunity Order Number: ' + Opportunity__r.OrderNumber__c + <br/>,
        NULL
    )
    

Related information:

How to conditionally display address data on the PDF?