


I'm trying to check whether ACM data field contains a particular string using if condition. However, that portion isn't working.
I have used below snippet. Can anyone please tell me if there's any issue with the snippet?
<% if ( (rtEvent.ctx.Consumer.PaymentMethod).includes("Direct Pay")) { %> <li>Order ID - <%=rtEvent.ctx.Consumer.OrderId%></li><% } %>
I have already checked value of rtEvent.ctx.Consumer.PaymentMethod -- it is having value 'Direct Pay' (including quotes).
I can't use "==" for "if" condition. Current value is 'Direct Pay' and after few weeks, it will be Direct Pay.
So I need to use "includes" or any similar method for checking.
Thank you for your help.
Views
Replies
Sign in to like this content
Total Likes
Hello @vinay16
You can use OR operator to check this.
Here is the sample code.
<% if(rtEvent.ctx.Consumer.PaymentMethod=="DirectPay" || rtEvent.ctx.Consumer.PaymentMethod=="'DirectPay'" || ) { %> <li>Order ID - <%=rtEvent.ctx.Consumer.OrderId%></li> <% } %>
Let me know if that works.
Hello @vinay16
You can use OR operator to check this.
Here is the sample code.
<% if(rtEvent.ctx.Consumer.PaymentMethod=="DirectPay" || rtEvent.ctx.Consumer.PaymentMethod=="'DirectPay'" || ) { %> <li>Order ID - <%=rtEvent.ctx.Consumer.OrderId%></li> <% } %>
Let me know if that works.
Thank you for suggestion, Manoj.
I will try this.
Meanwhile, is there anyway to check whether a string is there in the variable. Like "includes" or "contain" methods of JavaScript ?
This will improve the options for the future.
Thanks,
Vinay
Views
Replies
Sign in to like this content
Total Likes
Hello @vinay16
You can check it via the IndexOf method.
Here is an example.
var textString= "This is the Display Method"; if(textString.indexOf("Display") > 0){ document.write("Display is available in the string"); }else{ document.write("Display is not available in the string"); }
Thank you for your reply again.
I was not sure whether document. write works in ACM or not. Also, does indexOf works in ACM?
I know, outside of ACM, indexOf, contain and includes works. I'm finding it difficult to test these 3 in ACM. So, can you please confirm?
Views
Replies
Sign in to like this content
Total Likes
Views
Replies
Sign in to like this content
Total Likes
Thank you
Views
Replies
Sign in to like this content
Total Likes