Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to use operator "AND" in a conditional statement

donrgal
Level 1
Level 1

Hi there, 

 

I can't seem to find anything for an && condition. 

I have used an "OR" for now - but this won't work the condition that I need:

 

Landing page code snippet: 

 

<% if (recipient.mobilePhone== "" || recipient.phone== "" ) {%>
                <!-- Has either a Phone or Mobile only -->
                  <span class="nl-dce-field" id="span162503854014471" data-nl-expr="[recipient/@mobilePhone]">[Mobile]</span>
                  <span class="nl-dce-field" id="span162509825182771" data-nl-expr="[recipient/@phone]">[Phone]</span>. 
                 <% } else { %> 
                <!-- Has Phone AND Mobile  -->
                    <span class="nl-dce-field" id="span162503854014471" data-nl-expr="[recipient/@mobilePhone]">[Mobile]</span></strong> or
                    <strong class="badge-teal"><span class="nl-dce-field" id="span162509825182771" data-nl-expr="[recipient/@phone]">[Phone]</span>. 
 <% } %> 

 

4 Replies
ramon_bisswanger
Employee
Employee

Hi,

 

the && should indeed be what is needed.

What is the result if you are using this?

Any error shown or just the wrong behaviour?

donrgal
Level 1
Level 1

After further investigation, it seems that the expression for picking up the empty data isn't working.

 

For example:

Code:

<% if (recipient.phone== "") {%>
    <!-- Has either a Phone or Mobile only -->
        <p>Phone = IS empty:</p>
        <span class="nl-dce-field" id="span162503854014471" data-nl-expr="[recipient/@mobilePhone]">[Mobile]</span>
        <br/>
        <span class="nl-dce-field" id="span162509825182771" data-nl-expr="[recipient/@phone]"></span>[Phone]
     <% } else { %> 
    <!-- Has Phone AND Mobile  -->
        <p>Phone IS NOT = empty</p>
         <span class="nl-dce-field" id="span162503854014471" data-nl-expr="[recipient/@mobilePhone]">[Mobile]</span>
         <br/>
        <span class="nl-dce-field" id="span162509825182771" data-nl-expr="[recipient/@phone]">[Phone]</span>
<% } %> 

 

Result:

Data:
Phone: 9000 000
Mobile: 040000000
Data:
Phone:
Mobile: 040000000

Phone IS NOT = empty

040000000
9000 000

Phone IS NOT = empty

040000000

 

Any thoughts? 

 

ramon_bisswanger
Employee
Employee
hm, does the phone number potentially contains some empty string? What is the output of <%= recipient.phone.length %>
Sukrity_Wadhwa
Employee
Employee
Hi @donrgal, Were you able to resolve this query or do you still need more help here? Do let us know. Thanks!