SOLVED

Can you capitalize lead name token in email?

Go to solution
Anonymous
Not applicable

Can you capitalize lead name token in email?

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

Accepted Solutions
Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

@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

Re: Can you capitalize lead name token in email?

If you can do this, I'd love to know! 

Otherwise, I tend to take the time to standardize data using CRM fusion in Salesforce. 

Re: Can you capitalize lead name token in email?

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!
 
Level 2

Re: Can you capitalize lead name token in email?

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?

Re: Can you capitalize lead name token in email?

Did you check the checkbox on the right side of the velocity script and does the lead have a first name?

Level 2

Re: Can you capitalize lead name token in email?

Yes, to both. Unfortunately no luck.

Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

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.

Level 2

Re: Can you capitalize lead name token in email?

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

Level 10 - Community Moderator

Re: Can you capitalize lead name token in email?

Great x2!

Level 2

Re: Can you capitalize lead name token in email?

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?