Velocity Script - How to evaluate for several values in a field | Community
Skip to main content
Eric_Rex3
New Participant
June 9, 2021
Solved

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

  • June 9, 2021
  • 2 replies
  • 3375 views

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

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

 

2 replies

New Participant
June 9, 2021

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
Eric_Rex3Author
New Participant
June 14, 2021

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

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
June 9, 2021
#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) )

 

Eric_Rex3
Eric_Rex3Author
New Participant
June 14, 2021

 

Thanks, the edit worked perfectly!!!