Velocity Script for Company Name | Community
Skip to main content
Colby_Hooley
New Participant
August 7, 2020
Solved

Velocity Script for Company Name

  • August 7, 2020
  • 1 reply
  • 3415 views

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!

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

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}

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
August 7, 2020

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
New Participant
August 7, 2020

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
New Participant
August 7, 2020

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.