SOLVED

Velocity Script - How to evaluate for several values in a field

Go to solution
Eric_Rex3
Level 1

Velocity Script - How to evaluate for several values in a field

Dear Velocity Script masters,

 

I have a script where I am trying to evaluate if one of 3 values is present in a custom object field. If so then display a formatted date. Here is the script I have hacked together: 

 

I have recently added lines 6 and 7, attempting to include the values AC_G or AC_S in the evaluation. Basically, I want the script to function for values AC_P or AC_G or AC_S.  I have them commented out in this because as-is they do not work properly.  Is my syntax wrong or should this be accomplished in a different way?

 

#set( $exp = ${lDISales_cList.get(0).lDIExpireDate} )

#set( $interestingItems = [] )
#foreach( $item in $lDISales_cList )
#if( $item.lDIRenewalEffortNumber.equals("1") )
#if( $item.lDIOrderClass.equals("AC_P") )
##elseif( $item.lDIOrderClass.equals("AC_G") )
##elseif( $item.lDIOrderClass.equals("AC_S") )
#set( $void = $interestingItems.add($item) )

#set( $ExpireDate = $convert.parseDate($item.lDIExpireDate,'yyyy-MM-dd') )
##$date.format('MMM dd, yyyy', ${display.list($interestingItems,"<br>","<br>","lDIExpireDate")})##

##${display.list($interestingItems,"<br>","<br>","lDIExpireDate")}

${date.format('EEEE, MMMM dd, yyyy',$ExpireDate)}##
#end
#end
#end

 

 

Thanks much Marketo Engage superheros!

Eric

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script - How to evaluate for several values in a field

#if( $item.lDIOrderClass.equals("AC_P") || $item.lDIOrderClass.equals("AC_G") || $item.lDIOrderClass.equals("AC_S") )

 

or alternately, as it's more scalable

#set( $interestingOrderClasses = ["AC_P","AC_G","AC_S"] )
#if( $interestingOrderClasses.contains($item.lDIOrderClass) )

 

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script - How to evaluate for several values in a field

#if( $item.lDIOrderClass.equals("AC_P") || $item.lDIOrderClass.equals("AC_G") || $item.lDIOrderClass.equals("AC_S") )

 

or alternately, as it's more scalable

#set( $interestingOrderClasses = ["AC_P","AC_G","AC_S"] )
#if( $interestingOrderClasses.contains($item.lDIOrderClass) )

 

View solution in original post

Eric_Rex3
Level 1

Re: Velocity Script - How to evaluate for several values in a field

749956.png

 

Thanks, the edit worked perfectly!!!

Phillip_Wild
Level 10 - Community Advisor

Re: Velocity Script - How to evaluate for several values in a field

You might already know this @Eric_Rex3 , but just to double-check:

 

When you have an #if statement with #elseif conditions as well, the action you want the script to take should be after each evaluation, not at the end of all your #elseif evaluations. 

 

For example, this won't "do something" if $check1, $check2 or $check3 = 1. Only if $check3 = 1 since that line directly follows only that condition.

 

#if($check1.equals(1))
#elseif($check2.equals(1))
#elseif($check3.equals(1))
###do something
#end

 

So the below would accomplish the same thing as what Sanford posted, albeit less elegantly:

 

#if($check1.equals(1))
###do something
#elseif($check2.equals(1))
###do something
#elseif($check3.equals(1))
###do something
#end

 

Apologies if this is already known, I wasn't 100% sure from your code.

 

Eric_Rex3
Level 1

Re: Velocity Script - How to evaluate for several values in a field

Thanks Philip! I will try this out in other situations too. Appreciate the knowledge 🙂