Expand my Community achievements bar.

We are excited to introduce our latest innovation to enhance the Adobe Campaign user experience — the Adobe Campaign v8 Web User Interface!
SOLVED

Leveraging variables calculated in content block in Email Body

Avatar

Level 2

Hi all,

Context:

Transactional email through Message Center needing values calculated, mainly for date formatting purposes. There are multiple places where this is needed and in different formats.

Question:

Can all the variables be defined in a single content block and called in the body of the Email like in Adobe Campaign, e.g., <%= variable_name %>? Or do you have to create a content block for each instance?

Example: The bold text below needs to be reformatted from a single attribute from the payload. 

in payload: event date: 2022-06-07T12:52:09

in Email Body: 

June 07, 2022 * Location * 12:52

tracking url parameter: JUN:2022

 

Currently, I have created 3 separate content blocks for each displayed date / time. But having to create multiple content blocks for each Email could get unmanageable and wanted to understand if this can be consolidated, without having to do the entire email in the content block. 

 

Appreciate your help in advance,

Jim

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Turns out, you can do exactly that. Do the calculations in the content block. Include the content block in the body of the email, and use <% document.write(<variable name>); %> to render the variables in the email

View solution in original post

3 Replies

Avatar

Employee Advisor

Hi @JimXue 

This is the code you could use to format dates in a content block and then use the content block in the delivery

The date was formatted in the following way: (Monday 31 january 2010). Using different %D %B %4Y as format will result in different result...what format do you need?

<%
var utcTime = new Date(context.rtEvent.ctx.yourDate);

if (utcTime != undefined && utcTime != "")
{
var sDay = formatDate(utcTime, "%Al", "America/Chicago");
var sDate = formatDate(utcTime, "%D %B %4Y", "America/Chicago");
document.write(sDay + ", " + sDate);
}
else
document.write("");

 

Hope this helps,

Thanks

Denis

Avatar

Level 2

Hi @Denis_Bozonnet,

Thank you for replying. Yes, I have similar code in a content block already. But do you know if you are able to write the code for all three formats, and call the variable in the Email body. 

For example:

in content block--

var sDay = formatDate(utcTime, "%Al", "America/Chicago");
var sDate = formatDate(utcTime, "%D %B %4Y", "America/Chicago");

in Email code

<% document.write(sDay); %>

<% document.write(sDate); %>

after including the content block somewhere in the email of course?

 

Thanks!

Jim

Avatar

Correct answer by
Level 2

Turns out, you can do exactly that. Do the calculations in the content block. Include the content block in the body of the email, and use <% document.write(<variable name>); %> to render the variables in the email