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?
Views
Replies
Total Likes
@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<% } %>
Views
Replies
Total Likes
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: 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' && context.targetData.firstName == 'Sanjay') { document.writeraw("Na"); ' token=';& 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.
Views
Replies
Total Likes