SOLVED

Using multiple contains values in Velocity

Go to solution
Gally_Articola
Level 3

Re: Using multiple contains values in Velocity

Thanks! I removed the commas but am now getting a new error message:

Lexical error, Encountered: "m" (109), after : "." at *unset*[line 124, column 22] near

] )             
#foreach( $outputSet in $outputByCompany )             
#if( ${lead.Company}.matches($outputSet.pattern) )            
    #set($matchedOutputSet = $outputSet)     
    #break  

I tried removing a bunch of spaces in that section since the only "m" after "." is in ${lead.Company}.matches, but there's no extra spaces between those terms and I'm not sure where else to look. Here's the script:

#set( $outputByCompany = [             

{     

  "pattern" : "(?i)(.*)(^|,)\s*energysolutions|energysource|mhf services|energy solutions\s*(,|$)(.*)",      

  "speaker" : "goodbye"    

},     

{     

  "pattern" : "(?i)(.*)(^|,)\s*nuclear regulatory comm|nrc|usnrc\s*(,|$)(.*)",      

  "speaker" : "hello"   

},     

{     

  "pattern" : ".*",      

  "speaker" : "from ${lead.Company}"   

}     

] )            

#foreach($outputSet in $outputByCompany)            

#if(${lead.Company}.matches($outputSet.pattern))

#set($matchedOutputSet = $outputSet)

#break           

#end

#end

${matchedOutputSet.speaker}

SanfordWhiteman
Level 10 - Community Moderator

Re: Using multiple contains values in Velocity

Gally_Articola
Level 3

Re: Using multiple contains values in Velocity

Yes! That did it!

Thank you for all of your assistance! The script is running perfectly now!

Crystal_Pacheco
Level 4

Re: Using multiple contains values in Velocity

Hi Sandy,

I'm trying to get this script to work. I need a condition for if two choices are selected you get a different output:

Here is my code:

#set( $outputBysubscriptionFunction = [

{

"pattern" : "(?i).*\b(144322355954892&&187699601952849)\b.*",

"greeting" : "Choices 1 and 2"

},

{

"pattern" : "(?i).*\b(187699601952849)\b.*",

"greeting" : "Choice 1"

},

{

"pattern" : "(?i).*\b(144322355954892)\b.*",

"greeting" : "Choice 2"

}

] )

#foreach( $outputSet in $outputBysubscriptionFunction )

#if( $lead.NL_Subscriptions__c.matches($outputSet.pattern) )

#set( $matchedOutputSet = $outputSet )

#break

#end

#end

<span>${matchedOutputSet.greeting}</span>

The result I'm getting is Choice 2 for when two choices are selected. Am I close? What am I missing?

SanfordWhiteman
Level 10 - Community Moderator

Re: Using multiple contains values in Velocity

Pls move this to a new thread and I'll show you how it's done. You can refer back to this one. Better to separate distinct requirements, different correct answers.