velocity Script with if else condition is not working right

Anonymous
Not applicable

velocity Script with if else condition is not working right

HI,

I'm writing if else condition base on a custom object data, where if the customer matches it should show content A and if not, it should show content B. However both content A and B is showing up in the email. A shorten version of the code is below, any idea on what can be adjusted so it works correctly?

#foreach($customer in $customer_cList)

#if(${customer.customerID} == $matched)

show content A

#break

#else

show content B

#end

#end

4 REPLIES 4
Anonymous
Not applicable

Re: velocity Script with if else condition is not working right

How about this?  Also, you could try taking out the break

#foreach($customer in $customer_cList)

#if(${customer.customerID} == $matched)

show content A

#break

#else

#if(${customer.customerID} != $matched)

show content B

#end

#end

Nicholas_Manojl
Level 9

Re: velocity Script with if else condition is not working right

I don't think that makes much sense.

Forget about the loop.. keep it simple.

#if(${customer.customerID} == $matched)

show content A

#end

#if(${customer.customerID} != $matched)

show content B

 

#end

Anonymous
Not applicable

Re: velocity Script with if else condition is not working right

Thanks Jamie! I've tried that before but it didn't work right either. The reason I need to run a loop is because a customer needs to be matched up base on a certain membership level and they are associated with multiple membership level. For example I want any customer that has a gold membership to get content A. So if they have gold only OR gold AND silver they will get content A. If they have  Sliver only membership, they get content B.

Anonymous
Not applicable

Re: velocity Script with if else condition is not working right

Cindy,

if you are running a loop then you may have a batch campaign. where are you setting the $matched? why do you want to #break ? could it be $customer.matched?  here I how I used in my instance.

its a triggered campaign so using a trigger object.

#set($myPmtAmt = $!{TriggerObject.paymentAmount})

#if($myPmtAmt < 0)

  #set($SubjectMessage = "Refund Confirmation, ${lead.Email}")

#else

  #set($SubjectMessage = "Payment Confirmation, ${lead.Email}")

#end

$SubjectMessage

-Mahesh