2023.1 – Handling missing images

OL Learn Blog Automation

When dealing with dynamic images it is quite possible an image may not exist (or no longer exist). This article explains various scenarios to cope with these missing resources, including some techniques introduced in OL Connect 2023.1.


Fix images on beforehand

Use the Preflight option (located in the Context menu) to execute the template without producing output. It validates scripts but also checks for missing images. This helps you to identify and fix possible issues before running production output.

This approach may not be useful for all scenarios, especially when producing content in an automated environment. Let’s have a look at some other options to handle a missing resource for <img> elements.

Show alternate text

By default, missing images are omitted from the output (in older versions missing images showed a red cross). Setting alternate text which is shown in place of the image if the image does not exist or fails to load.

To set alternate text for an image:

  1. Select the image in the main editor.
  2. Enter a description in the Alternate text field located in the Attributes panel.

Show a fallback image

If an image does not exists, you might as well replace it with a new one. When an image is missing the data-broken-image attribute is added to the <img> element to specify that the image is broken. This can be used in the selectors of scripts and CSS to apply custom styling or to insert a custom fallback image.

To select these images in a script use this ‘data’ selector: [data-broken-image]. The following script replaces the ‘broken image’ with a fallback image stored in the Images folder of the Resources panel:


Note! Due to technical reasons the alternate text takes precedence over a scripted fallback image.

Cancel the job

The [data-broken-image] selector can also be used to terminate the content creation run and propagate the error and its message back to the client. This provides you with more control on when to stop producing output.

The following script throws a fatal error:

fatalError('Missing images')

When using Content Creation plugins in OL Connect Workflow one can setup of follow-up actions in the On Error tab of the respective step. In case of OL Connect Automate (Node-RED) this is achieved using a Catch node.

Skipping content items

With a little help of a Job Preset content items with missing images can be skipped. Again, this is achieved by a script with the [data-broken-image] selector.

The following script writes a custom property to the content item to specify the document contains a broken image. In addition, it writes the path of the image and some extra information about the customer to separate properties.

contentitem.properties.missingImage = true
contentitem.properties.image = this.attr('src')
contentitem.properties.customerId = record.fields.customerId
contentitem.properties.batchId = record.fields.batchId

Next create a Job Preset and enable the Apply Filtering and sorting to record selection option. Add a property rule and set the key to the name of the property to missingImage. Now change the condition to is not set.

Use this Job Preset in OL Connect Workflow (or in the Print dialog of OL Connect Designer) to generate output where the content items with missing images are skipped. The extra properties stored on the content items can be used to retrieve the affected records using the Retrieve Items task. This information can be used to investigate the missing images and do a new run for those records after fixing the images.

Tagged in: Images, Scripting

Leave a Reply

Your email address will not be published. Required fields are marked *