SOLVED

Re: Can you capitalize lead name token in email?

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

It's probably a carriage return, not a space -- then coerced to a space by HTML.

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

Whitespace is often (depending on context) preserved in Velo, which can lead to fun times.

Noah_Wong1
Level 2

Re: Can you capitalize lead name token in email?

Yup, that worked. Thanks again!

Ayush_Aggarwal1
Level 2

Re: Can you capitalize lead name token in email?

Hi Sanford Whiteman‌,

Thank you for sharing it. This is helpful and it worked. However, even after adding ## in the end of the code, the whitespace still appears. Can you help me please on how to remove the extra spaces?

Regards,

Ayush Aggarwal

SanfordWhiteman
Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

If your code is exactly like the above, the whitespace isn't coming from Velocity. 

Kim_Gandy1
Level 7

Re: Can you capitalize lead name token in email?

Hi @SanfordWhiteman, can you clarify how to wrap in isEmpty() ? How should the final velocity script look combining the two scripts? 

 

Script #1

#set($name = ${lead.FirstName})
$name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()

 

Script #2

#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end
SanfordWhiteman
Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

Could you highlight your code (as Java) please using the Syntax Highlighter here on the forum?

Kim_Gandy1
Level 7

Re: Can you capitalize lead name token in email?

@SanfordWhiteman, updated. 

Kim_Gandy1
Level 7

Re: Can you capitalize lead name token in email?

Correct combined scripts:

#set($name = ${lead.FirstName})
#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end
SanfordWhiteman
Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

One little thing. 🤓 You shouldn't use curly braces in directives (#set), only in output. (They happen to work in this simple case, but as code gets more complex they lead to syntax errors.)

 

#set( $name = $lead.FirstName )
#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end

 

Anonymous
Not applicable

Re: Can you capitalize lead name token in email?

Justin, thank so much, I've been trying to figure this one out. I'll try it.
cheers,