how to check option condition in email template script | Community
Skip to main content
Level 2
January 18, 2024
Solved

how to check option condition in email template script

  • January 18, 2024
  • 2 replies
  • 1132 views

Hi team,

I have to check if the option value is 0 my email template prints "Hi" and if the option value is 1 it prints "Bye". this scenario I want to be achieve in an email template not using a Personalization block.

My code below:

<%
var A = "<%@ include option='test' %>

if (A == '0')
{

<p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">hi</span></b></p>

}
else
{
<p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">bye</span></b></p>
}

%>

 

error:

01/18/2024 3:00:53 AM Failed Unreachable xxx Error while compiling script 'content htmlContent' line 8: illegal XML character (line='var A = <%@ include option='test' %>;\ ' token='%@ include option='test' %>;\ '). SCR-160032 Javascript&colon; error while compiling script 'content htmlContent'. JST-310007 Unable to compile script (content htmlContent).

 

@parthasarathy  please help on this 

 

 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by LakshmiPravallika

Hi @kumar_27 ,

 

Please try by adding the below code in the Script Tab of your Reccuring Delivery 

var test="";

if(getOption("yourOptionName") == 0)
{
test=0;
}


logInfo("test var value"+test)

 

and in your Reccuring delivery , Please use the below code snippet

 

<% if(test = '0' ) { %><p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">hi</span></b></p><% }
else { %><p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">bye</span></b></p><% } %>

 

Regards,

Pravallika.

2 replies

AkshayAnand
Community Advisor
Community Advisor
January 18, 2024

Hi @kumar_27 

 

Could you try defining the variables [var A = <%@ include option='test' %>]under the script tag <script> ..... </script>  in your HTML code and use the below code in your body tag.

<% if (A == '0') { %> <p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">hi</span></b></p> <% } else { %> <p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">bye</span></b></p> <% } %>

 

Thanks,

Akshay

Kumar_27Author
Level 2
January 18, 2024

hi @akshayanand 

 

 I got the below error while I tried the above method. 

 

Error while compiling script 'content htmlContent' line 7: A is not defined. SCR-160012 Javascript&colon; error while evaluating script 'content htmlContent'.

LakshmiPravallika
Community Advisor
LakshmiPravallikaCommunity AdvisorAccepted solution
Community Advisor
January 18, 2024

Hi @kumar_27 ,

 

Please try by adding the below code in the Script Tab of your Reccuring Delivery 

var test="";

if(getOption("yourOptionName") == 0)
{
test=0;
}


logInfo("test var value"+test)

 

and in your Reccuring delivery , Please use the below code snippet

 

<% if(test = '0' ) { %><p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">hi</span></b></p><% }
else { %><p><b><span style="font-family: 'Times New Roman'; font-size: 16px;">bye</span></b></p><% } %>

 

Regards,

Pravallika.