AnsweredAssumed Answered

Velocity Script - Clean Up First Name Field

Question asked by Broderick Klemetson on Mar 2, 2018
Latest reply on Mar 5, 2018 by Broderick Klemetson

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?

Outcomes