Expand my Community achievements bar.

SOLVED

Conditional statement transactional message center not working

Avatar

Level 2

Dear Community,

I have been trying to implement conditional statement but it doesn't work for me.

Can you suggest what's wrong?

 

Original method
<% if ( toString(rtEvent.ctx.@freeText22).length > 0 ) { %>
<tr>
<td class="mpbx-27" style="font-size:16px; line-height:22px; font-family:'Core Sans C', Helvetica, Arial, sans-serif; font-weight: 400; text-align:left; min-width:auto !important; color:#151515; padding-bottom: 20px;">
<strong>Sources</strong><br />
<%= rtEvent.ctx.@freeText22 %>
</td>
</tr>
<% } %>

 

New method
<% var ctx = XML(rtEvent.ctx); %>
<% if ( rtEvent.ctx.@freeText22 == true ) { %>
<tr>
<td class="mpbx-27" style="font-size:16px; line-height:22px; font-family:'Core Sans C', Helvetica, Arial, sans-serif; font-weight: 400; text-align:left; min-width:auto !important; color:#151515; padding-bottom: 20px;">
<strong>Sources</strong><br />
<%= rtEvent.ctx.@freeText22 %>
</td>
</tr>
<% } %>
<%} else { %>
<%}%>

 

Thanks!!

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @AkshayAnand 

Finally, it works!!!

trim is the missing keyword!

srvphoenix_2-1675268352500.png

Thanks for your support!

Cheers

Snehil

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @srvphoenix 

 

If you want to do a comparison to a string "TRUE", then please insert the string in single inverted commas and try.

If you want to give a boolean check of true or false, then you can use numerical values 0(false) 1 or any positive value (true) to check the if block.

 

Eg :-

if (abc == 'true') --> string comparison

if (abc = 1 ) --> check for true condition

if (abc = 0) --> check for false condition

 

Also Could you please check the brackets, I can see an extra closing bracket in the above code.

 

Regards

Akshay

Avatar

Level 2

Hi Akshay,

 

Thanks for your input.

 

I tried again your suggestions but no matter what I put in the if else condition, I always get the else statement (even with negation). I tried =="true" with and without quotes, boolean logic, ! to get inversion, NULL but none work with Transactional emails.

 

Do you have a working sample along with a payload that you can show?

 

Thanks again!

Snehil Singh

Avatar

Community Advisor

Hi @srvphoenix 

 

Please find the working code at our end.

AkshayAnand_0-1675233707702.png

Another example

AkshayAnand_1-1675233769498.png

 

Also could you please try  rtEvent.ctx.freeText22 == 'true' once as the dot location for new parent field is .field and for child elements inside the field is .field@childElement

 Please let me know if it works.

 

Regards

Akshay

Avatar

Correct answer by
Level 2

Hi @AkshayAnand 

Finally, it works!!!

trim is the missing keyword!

srvphoenix_2-1675268352500.png

Thanks for your support!

Cheers

Snehil