Skip to main content
New Participant
Nov 19, 2025 5:04 PM UTC
Question

Conditional statement transactional message center issue

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

ParthaSarathy
New Participant
Nov 20, 2025 5:37 PM UTC

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,

 

For Valid records,

Translate
 ~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups
SanjayNaAuthor
New Participant
Nov 21, 2025 2:51 PM UTC

Thanks ParthaSarathy, that seemed to do the trick.

Translate
Level 2
Nov 20, 2025 12:23 PM UTC

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.

Translate