Custom Object VTL #foreach loop, #if #else | Community
Skip to main content
New Participant
December 11, 2020
Question

Custom Object VTL #foreach loop, #if #else

  • December 11, 2020
  • 1 reply
  • 1980 views

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
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
New Participant
December 12, 2020

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.