In a previous article about Repeaters for Emails in Marketing Cloud Growth and Advanced, we took the example of a boat rental company, sending an email listing previous reservations.
The reservations are part of the Data Graph and they contain the image URL to display for each reservation record.
In this article, we will focus on sending an email, presenting the current reservation model. This is what we are trying to achieve (we’ll focus on displaying the dynamic image, not on the body copy here):
Method #1 – Using the default Image Component
So, the first step, once the Email is created, is to add an Image Component into the canvas. You can drag it from the left sidebar, under Media or click the + sign in the canvas.
Once the email is in the canvas, we are presented, on the right sidebar, in the Select Image Source section, the option to add an image from the CMS (a static one), or using a Merge Field. It is this latter option we will choose, since the image URL is stored as field in our Data Graph.
So, we click the Add Merge Field option, and navigate through our Data Graph, to reach our Image URL.
But, no luck, it is not presented, even though actually in the Data Graph (Boat Thumbnail):
So, why can’t we add it as Merge Field in the image Component? Well, the answer to this is that the URL format is not supported, it needs to be a text field. In Salesforce, our field for storing the images in a reservation is an URL type, when creating the DSO we just used the defaults.
So, to solve this, we’ll create a new Formula field in our DSO, basically a copy of the URL, but with the Text Format. In our example, we call it Boat Preview, and declare it that way:
Once done, we need to:
- Map that text Field to a new Field in our DMO (same type)
- Add the Field in the Data Graph, by editing it
- Force the evaluation of new the Formula Field (the simplest is to mass update the reservations and manually trigger a refresh of the DSO)
- Force the refresh of our Data Graph
We then have this is for a specific reservation record:
In case you wonder, this images are stored in the CMS, and their addresses stored in Salesforce are obtained by following the 6th recipe of our CMS optimisations article.
Also, if your record is the DMO, but not in the Data Graph, this is probably due to the fact that Engagement DMOs records older than 30 days are ignored by the Data Graph.
Then we can go back to our Email Editor, and now see with the text Fields, which we will use.
So let’s insert it. Depending on wether there can have multiple records of reservations, you need to select which record to display (or use Repeaters in the exact same way);
We are all set, now, to Preview our work. Do not forget to Save the Email before previewing it, otherwise the Merge Field disappears. Et voilà 😎
Method #2 – Using an HTML component
In this method, we don’t drag an Image Component into the canvas, but an HTML component, in which we will add the Dynamic Image. This gives you the complete control on how you want the image to look.
The steps are exactly the same as the one described in the first method. But, doing so the HTML complains that the src attribute should contain a value starting with “https://”. Obviously, this is made for static image. Hopefully, it also supports Dynamic URLs, but we’ll need to do some extra work.
First, let’s make the component happy by adding the correct scheme at the beginning of the src attribute.
But, doing so, the image would not display, as the URL would actually be malformed (starting with two “https://” schemes).
To tackle this, we’ll simply edit the definition of our text Formula field (or create a new one) by using the following Formula:
REPLACE(sourceField['Boat_Thumbnail__c'], 'https://', '')
We can ensure this works as intended with the Test Button of the Formula Fields (enter a value, click test and see the result in the Output section).
We then to go through the exact same steps as the ones from the first method to refresh our Data Graph, so now the URL has the correct formatting to be handled by the HTML component.
Once done, we don’t forget to save our work before previewing the email for a given reservation. It works too 😎