Velocity Script - Clean Up First Name Field | Community
Skip to main content
Broderick_Klem1
New Participant
March 2, 2018
Solved

Velocity Script - Clean Up First Name Field

  • March 2, 2018
  • 1 reply
  • 5134 views

I'm currently use this email script token to clean up our first name field which often contains email addresses, periods, full names, and title case it, etc.

#if($lead.FirstName == "") 

  there##

#elseif($lead.FirstName.contains("@")) 

  there##

#elseif($lead.FirstName.contains("."))

  there##

#elseif($lead.FirstName.contains(" "))

  #set($name = $lead.FirstName.split(" ")[0])

  $name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()##

#else  

  #set($name = $lead.FirstName)

  $name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()##

#end

The one thing I can't figure out how to do is to identify when a first name field contains less than 2 characters so that on line #07 where we split the name, if the subsequent $name < 2 characters (e.g. "A Johnson" becoming "A") then just use "there". How do I do that?

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

First, note this approach doesn't work for people with hyphenated first names. "Jean-Marie" should not be changed to "Jean-marie," that's not right.  (Similarly, people with a compound first name may not use a hyphen, like "Norma Jean," but that's the first name just the same, not "Norma.")

As for determining if something has N characters:

#if( $name.length() > 2 )

$display.capitalize($lead.FirstName.toLowerCase())##

#else

there##

#end

But there, too, you're saying that "AJ" and "B.B." aren't people's real-life first names.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
March 2, 2018

First, note this approach doesn't work for people with hyphenated first names. "Jean-Marie" should not be changed to "Jean-marie," that's not right.  (Similarly, people with a compound first name may not use a hyphen, like "Norma Jean," but that's the first name just the same, not "Norma.")

As for determining if something has N characters:

#if( $name.length() > 2 )

$display.capitalize($lead.FirstName.toLowerCase())##

#else

there##

#end

But there, too, you're saying that "AJ" and "B.B." aren't people's real-life first names.

Broderick_Klem1
New Participant
March 5, 2018

Thanks! And yeah, it's definitely not perfect, but I think saying "Hi there," a to a few "AJ"s is an acceptable trade off for to not ever having obviously bad names, especially when the email is supposed to look like it's coming from a person.