SOLVED

Re: Velocity Script for Company Name

Go to solution
Colby_Hooley
Level 1

Velocity Script for Company Name

Hi everyone!

 

I'm trying to create a velocity script that does the following. 

 

If company name contains (starts with would also be helpful) "University" display the company name as "the University" otherwise display the current company name value. 

 

In my beginner attempts I tried this but I'm obviously missing some critical steps. 

#if (!$lead.Company.contains("university")())
#set ($companyName = "the ${lead.Company}")
#else
#set ($companyName = "${lead.Company}")
#end
${companyName}

 

Any suggestions/feedback is greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script for Company Name

Well, you have extra parentheses in there — so it's a fatal syntax error right away.

 

!$someString.contains means "not contains," which seems the reverse of what you said you want?

 

Also pretty sure you're expecting case-insenstitivity.

 

So more like

#if( $lead.Company.matches("(?i).*university.*") )
#set( $companyName = "the ${lead.Company}" )
#else
#set( $companyName = "${lead.Company}" )
#end
${companyName}

 

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script for Company Name

Well, you have extra parentheses in there — so it's a fatal syntax error right away.

 

!$someString.contains means "not contains," which seems the reverse of what you said you want?

 

Also pretty sure you're expecting case-insenstitivity.

 

So more like

#if( $lead.Company.matches("(?i).*university.*") )
#set( $companyName = "the ${lead.Company}" )
#else
#set( $companyName = "${lead.Company}" )
#end
${companyName}

 

Colby_Hooley
Level 1

Re: Velocity Script for Company Name

Thank you! That was great. I got it to return "University of Kuali", my test records company name. But I can't get it to return "the University of Kuali" even though it matches the logic. Is there something else I might be missing? 

 

Thanks again!

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script for Company Name

It outputs "the University of Kuali" for me when the Company is "University of Kuali".

 

Of course it'll also output "the The University of Kuali" if the Company is "The University of Kuali", but that's another matter. You probably need more robust logic than you were first thinking.

Colby_Hooley
Level 1

Re: Velocity Script for Company Name

Crazy, must have just not refreshed the page as I thought with the email. It's working for me now too. I agree, I've created a secondary problem by solving the first haha. I appreciate you taking the time to respond, Sanford!