SOLVED

Can you capitalize lead name token in email?

Go to solution
Anonymous
Not applicable
If a lead enters their name in lowercase (john doe), how can I capitalize that token in an email (John Doe)? Is this something that can be fixed in form settings or should it be fixed in the HTML? I'm currently trying to fix it (unsuccessfully) in the HTML using the following:
<p><span class="text-transform:capitalize">Hey {{lead.First Name:default=there}}</span>,</p>

I have no coding background, so the HTML could be wrong. Any help is greatly appreciated!
 
Tags (1)
1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator
@Tyler G also, the correct CSS would be 

style="text-transform: capitalize;"

However, this will be rendered in Outlook Web Access as if you used 'uppercase' (don't ask me why -- 'capitalize' has no kind of security implication I can think of).  By contrast, it works in Gmail.  YMMV.

 

View solution in original post

26 REPLIES 26
SanfordWhiteman
Level 10 - Community Moderator
@Tyler I think you're right, Spark doesn't include "Advanced dynamic content."
Anonymous
Not applicable
Thank you for all the input and helpful responses. I'm glad to see I'm not the only one with this question!

The CSS fix suggested by Sanford fixed this for me, however I'll have to look into the Outlook issue.

I'm using this for an autoresponder in an engagement program (thus looking for a more real-time solution) and want it to look more "personal" and less like an automatic canned response. I'm looking into Justin's response too, however I can't seem to find email scripts in the Tokens. We are currently using Spark which might be the issue. 

As for the cultural issues, we are only using first names so hopefully this doesn't become an issue. It's good to keep in mind though. It's never good to insult potential customers with our first interaction!
SanfordWhiteman
Level 10 - Community Moderator
Before taking the risk of culturally inappropriate "fixup" I suggest everybody read this comment from a person who understands the issues:

Quote:
French, German, and Dutch surnames among others may have prefixes like
"von", "de", and "van".  These may be separable ("van der Steen" is
alphabetized under "S") or an inherent part of the name, in which case
they are generally capitalized.  Getting this wrong may be insulting or
confusing.
Anonymous
Not applicable
I like the way Aweber handles this, as it would be suitable to my ultimate goal. What Aweber does is allow you to select the token which runs the script to normalize title case on First Name, Last Name or FirstName/LastName in the asset you place the token within. That would work well for my requirement.

 
SanfordWhiteman
Level 10 - Community Moderator
@Tyler G also, the correct CSS would be 

style="text-transform: capitalize;"

However, this will be rendered in Outlook Web Access as if you used 'uppercase' (don't ask me why -- 'capitalize' has no kind of security implication I can think of).  By contrast, it works in Gmail.  YMMV.

 
SanfordWhiteman
Level 10 - Community Moderator
I second Josh: if I lazily entered my name, it can even feel more intimate to have it left as-is.

Moreover, if this is lead-entered data, they know best how to spell their name.  You probably won't go wrong by capitalizing the first name (ignoring for the moment for the fact that the "first' name presented is the family name in some cultures).  But you can't just go capitalizing last names like "van Helsing" or "de la Fuente"!  Then you just seem culturally ignorant.  A data cleaning system can apply intelligence to this process, but it is not guaranteed.
Josh_Hill13
Level 10 - Champion Alumni
I'd setup a data cleaning system as Kristen suggests. I like the scripting idea, but you really should have some bot running in your CRM to fix this sort of thing.

But honestly, I'm never offended if that happens - because it was me who did the lowercase 😉
Anonymous
Not applicable
Justin, thank so much, I've been trying to figure this one out. I'll try it.
cheers,
Justin_Cooperm2
Level 10
It's Friday afternoon so I'll help you out!

You can use basic Java string manipulation in an Email Script token to do this. In your email program, click the "My Tokens" tab. Create a new Email Script token and name it what you'd like. In the script, enter:

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


Note: Make sure you check the "First Name" checkbox in the right-hand tree under "Lead"!

Save the token and in your email asset, reference it as {{my.TokenName:default=Friend}} anywhere you like. It will output the first name of the lead with the first letter capitalized!

Email Scripts are your friend! Happy Marketing!
 
Noah_Wong1
Level 2

I keep getting this error message:

An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!

Invocation of method 'substring' in class java.lang.String threw exception java.lang.StringIndexOutOfBoundsException: String index out of range: 1 near

Any thoughts?

SanfordWhiteman
Level 10 - Community Moderator

Hi Noah,

This is Velocity in a nutshell (and don't get me wrong, I love it, it's just quirky): flexible when you don't need it to be, and strict when you don't expect it!

When Velocity calls deep enough into the outer Java environment, you can get error conditions where you might've thought Velo would let you slide.

A prime example is when you try to take the substring of an existing variable that is empty, with any index other than 0:

#set( $a = "" )

$!{b.substring(0,1)} <-- no error!

$!{a.startsWith("ABCDE")} <-- no error!

$!{a.substring(0,1)} <-- error!

Note how calling substring() on the nonexistent variable $b doesn't cause an error, but the substring on existing-but-empty $a is an error. This is what I mean by the flexible vs. strict dichotomy being kind of surprising.

To avoid this error, wrap in isEmpty():

#if( !$name.isEmpty() )

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

#end

Also see my comments here​, and if you're getting into VTL in Marketo you should read and/or subscribe to my blog, if I do say so. See my VTL posts at http://blog.teknkl.com/tag/velocity.

Oh, and also it's almost always better to open a new thread (you can link back to an old one for reference). Old threads can never be closed by anyone but the OP, and more than one answer can never be marked Correct.

Kim_Gandy1
Level 7

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
Kim_Gandy1
Level 7

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

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

 

SanfordWhiteman
Level 10 - Community Moderator

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

Kim_Gandy1
Level 7

@SanfordWhiteman, updated. 

Noah_Wong1
Level 2

Hi Sanford,

Success! Thanks so much for the help. Brand new to Velocity but your reply explains things very clearly.

I've subscribed to your blog!

Thanks,

Noah

SanfordWhiteman
Level 10 - Community Moderator

Great x2!

Noah_Wong1
Level 2

One more quick question about this script.

This appears to add an extra space after the token. For example, the output is "Dear XXX ,"

How can I remove that space in between the end of the name and the comma?

SanfordWhiteman
Level 10 - Community Moderator

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.