SOLVED

Set URL variable from value found in string Velocity Script

Go to solution
John_Potter1
Level 2

Set URL variable from value found in string Velocity Script

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Set URL variable from value found in string Velocity Script

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‍‍‍‍‍‍

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Set URL variable from value found in string Velocity Script

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‍‍‍‍‍‍
John_Potter1
Level 2

Re: Set URL variable from value found in string Velocity Script

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Set URL variable from value found in string Velocity Script

Hello OP?