I am trying to set a URL variable based on a specific value found within a string value from a Person Object. The Person Object field values are separated by a "|" character for example: |test1|test2|test3|. The Person Object is also checked in the tree on the right column of the Velocity Script modal window. I have tried using .contains and .matches using regex, but, I have not had much luck. Below is a sample of my Velocity Script, the IF statement never returns true when I know the lead I am testing contains the value I am comparing against. The ELSE statement is returned each and every time. The Email I am testing is being tested being sent as a "Person". What could I be doing wrong?:
## value looking form in string
#set( $stringVal = "test1" )
## check if the lead has above value
#if( $lead.personObject.matches("(\|)\s*${stringVal}\s*(\|)") )
#set($browserURL = "www.exampleURL1.com")
## otherwise lead does not have above value
#else
#set($browserURL = "www.exampleURL2.com")
#end
I have also tried:
## value looking for in string
#set ( $stringVal = $lead.personObject.split("|") )
## check if the lead has above value
#if($stringVal.contains("test1"))
#set($browserURL = "www.exampleURL1.com")
## otherwise lead does not have above value
#else
#set($browserURL = "www.exampleURL2.com")
#end
Thanks in advance.
Solved! Go to Solution.
It's kind of confusing to talk about "from a Person Object" if (for our purposes in Velocity) it's a flat String field on the $lead.
Anyway, | is a reserved character in regexes. You have to escape it.
#set ( $personObjectValues = $lead.personObject.split("\|") )
#if( $personObjectValues.contains("test1") )
#set($browserURL = "www.exampleURL1.com")
#else
#set($browserURL = "www.exampleURL2.com")
#end
It's kind of confusing to talk about "from a Person Object" if (for our purposes in Velocity) it's a flat String field on the $lead.
Anyway, | is a reserved character in regexes. You have to escape it.
#set ( $personObjectValues = $lead.personObject.split("\|") )
#if( $personObjectValues.contains("test1") )
#set($browserURL = "www.exampleURL1.com")
#else
#set($browserURL = "www.exampleURL2.com")
#end
Hi Sanford,
Thanks for the quick reply and thank you for being that extra set of eyes. I think working and troubleshooting this for as long as I had, my eyes just grew tired and overlooked the obvious. The escaped "|" makes sense and did work as expected.
Thanks again for all you contribute to these forums