Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards

Conditional statement transactional message center issue

Avatar

Level 1

I have been testing out conditional content within our transactional message in V8 however I can't seem to get it to work when there is a 'Null' condition present. The piece of Javascript I am using is:

 

<% if (ctx.@Variable_Name != '') { %>show HTML content<% } else { %>show other HTML content<% } %>

 

When I use 

<% if (ctx.@Variable_Name != 'variable name') { %>show HTML content<% } else { %>show other HTML content<% } %> 

 

it seems to work fine however when I change it to a blank input it fails again. What am I doing incorrectly in the transactional message HTML editor compared to the normal delivery HTML editor as the same piece of code works there (obviously changing the variable name to be targetData rather than ctx)

3 Replies

Avatar

Level 3

I always get confused about how to check for empty/null in Message Center. How about trying something like:

<% if (ctx.@Variable_Name != '' && ctx.@Variable_Name != null && ctx.@Variable_Name != undefined) { %>show HTML content<% } else { %>show other HTML content<% } %>

Sorry if the syntax is not quite right, I'm not at my desk right now to test this.

Avatar

Community Advisor

Hi @SanjayNa ,

Use the below script,

<% if ( String(ctx.Variable_Name).length > 0 ) { %>
<p>Content for Variable_Name exist</p>
<% } else { %>
<p>Content for Missing Variable_Name</p>
<% } %>

For Null variable,

ParthaSarathy_0-1763660050806.png

 

For Valid records,

ParthaSarathy_1-1763660189197.png

Avatar

Level 1

Thanks ParthaSarathy, that seemed to do the trick.