Re: Custom Object VTL #foreach loop, #if #else

bchatham
Level 1

Custom Object VTL #foreach loop, #if #else

Hi, 

I have a record the qualifies for the if statement of the below VTL script. However, the output is always presenting the else statement value. Can some please advise. 

 

#foreach( $item in $marketoLeadAutoEmail_cList )
#if(
$item.CEM == 'N'
&& $item.EHS_AFFILIATE == 'N'
&& $item.STATUS_CODE == 'L1'
)
#set($Affiliate_Id =$item.ALLIANCE_ID)
#else
#set($Affiliate_Id = 'afdfv')
#break
$Affiliate_Id
#end
#end
1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Object VTL #foreach loop, #if #else

First, let's fix up your syntax a bit. You don't want to use the == (it's broken in subtle ways) but rather the .equals() method.

#foreach( $item in $marketoLeadAutoEmail_cList )
#if( $item.CEM.equals("N") && $item.EHS_AFFILIATE.equals("N") && $item.STATUS_CODE.equals("L1") )
#set( $Affiliate_Id = $item.ALLIANCE_ID )
#else
#set( $Affiliate_Id = "afdfv" )
#break
${Affiliate_Id}
#end
#end

 

Anyway, you haven't provided enough info (like a dump of all the fields on $item) but you're failing to break when a match is found. You only break when a match is not found.