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!

Using logical operators and conditional statements within the email editor of Adobe Campaign Standard

Avatar

Level 1

Hi team,

 

I have been having some trying to get a piece of javascript working within the HTML section of the email editor in ACS. Currently, when I execute a delivery with this code in it the delivery sends fine:

 

<% if (context.targetData.lastName == 'Ross' && context.targetData.firstName == 'Bob') { %>Bob<% } else if (context.targetData.lastName == 'Smith' && context.targetData.firstName == 'John') { %>John<% } else if (context.targetData.lastName == 'Williams' && context.targetData.firstName == 'Robbie') { %>Robbie<% } else { %>Hancock<% } %>

 

. However when I change the operator to an 'OR' statement the delivery errors out.

 

<% if (context.targetData.lastName == 'Ross' || context.targetData.firstName == 'Bob') { %>Bob<% } else if (context.targetData.lastName == 'Smith' && context.targetData.firstName == 'John') { %>John<% } else if (context.targetData.lastName == 'Williams' && context.targetData.firstName == 'Robbie') { %>Robbie<% } else { %>Hancock<% } %>

 

Does anyone know what is wrong with the second piece of code?

2 Replies

Avatar

Community Advisor

@SanjayNa I tested below code snippets in the email template and it works fine.

<% if (context.profile.lastName == 'Ross' || context.profile.firstName == 'Bob') { %>Bob<% } else if (context.profile.lastName == 'Smith' && context.profile.firstName == 'John') { %>John<% } else if (context.profile.lastName == 'Williams' && context.profile.firstName == 'Robbie') { %>Robbie<% } else { %>Hancock<% } %>

----------------------------------------------------

<% if (context.profile.lastName == 'Ross' || context.profile.firstName == 'Bob') { %>Bob<% } else if (context.profile.lastName == 'Smith' || context.profile.firstName == 'John') { %>John<% } else if (context.profile.lastName == 'Williams' || context.profile.firstName == 'Robbie') { %>Robbie<% } else { %>Hancock<% } %>

----------------------------------------------------

<% if (context.profile.lastName == 'Ross' && context.profile.firstName == 'Bob') { %>Bob<% } else if (context.profile.lastName == 'Smith' && context.profile.firstName == 'John') { %>John<% } else if (context.profile.lastName == 'Williams' && context.profile.firstName == 'Robbie') { %>Robbie<% } else { %>Hancock<% } %>

Thanks, Sathees

Avatar

Level 1

Thanks @SatheeskannaK ,

 

I tried to input the top code however that didn't work. I keep receiving this particular error message when I try to add multiple else if statements: 

01/07/2024 16:03:27
SCR-160032 Javascript&colon; failure while compiling script 'TemplateCheck'.
01/07/2024 16:03:27
JST-310000 Error while compiling script 'TemplateCheck' line 358: missing ) after condition (line=' if (context.targetData.appHVAmodule == 'Na' &amp;&amp; context.targetData.firstName == 'Sanjay') { document.writeraw("Na"); ' token=';&amp; context.targetData.firstName == 'Sanjay') { document.writeraw("Na"); ').

 

Ignore the data for targetData.appHVAmodule as I have created this variable myself and was testing it out - this is a string variable.