Re: Splitting field data in token

Nicol_Maurer
Level 3

Splitting field data in token

Has anyone written a token script that will return only part of a data field? I use our Salesperson token often, which will return their full name. I would like to make it a little more personal by only returning the first name. I've tried scripts to split the data in the field, returning only what it before the first space in the field, but have had no luck. I'm not a developer, nor do I have one at my disposal--so my knowledge of how to use what I find on the Internet is limited. Please let me know if anyone has accomplished this.

9 REPLIES 9
Nicol_Maurer
Level 3

Re: Splitting field data in token

Right now I have:

#set ($name = ${lead.Salesperson})

#set ($repfullname = $name.split(" "))

$repfullname[0]

Returns: $repfullname[0]

Anonymous
Not applicable

Re: Splitting field data in token

Have you tried using the substring method?  I think that will solve it.

Nicol_Maurer
Level 3

Re: Splitting field data in token

Thanks for your reply. I'm actually trying to get the {lead.Salesperson} value assigned to the $name variable. It's not currently assigning, or if it is, it's being assigned as an object and not a string.

Jenna_Molby10
Level 3 - Champion Alumni

Re: Splitting field data in token

Your logic is correct. What displays in the email when you do a test send?

Nicol_Maurer
Level 3

Re: Splitting field data in token

It just displays ' $repfullname[0]'.

When I assign lead.SalesPerson to $name the value of $name isn't what is expected.  It's blank.  If I give lead.SalesPerson a default value it will display the default value.  It seems a bit buggy. I also tried an example script that was available here in the forum:

Example 1: Properly Capitalizing First Name

#set ($fname = ${lead.FirstName})

#if($fname.equals(""))

Friend

#else

$display.capitalize($fname)

#end

This didn't work either.

Anonymous
Not applicable

Re: Splitting field data in token

Hi Nicol Maurer

Did you get this working?

I think your question was that the script you had placed not showing value in display. Did you actually try sending this email to a test lead?

Please let me know if you need help. There are a couple of gotcha's w.r.t. testing and debugging velocity scripts in Marketo.

Rajesh Talele

Robb_Barrett
Marketo Employee

Re: Splitting field data in token

You should also force it to lower case, then force it to title case, just in case someone enters an ALL CAPS NAME or a lower name oR SoMe weiRd MIX

#set ($lowername =  $repfullname[0].toLowerCase())

#set ($propercase = $lowername.substring(0,1).toUpperCase())

Robb Barrett
Nicol_Maurer
Level 3

Re: Splitting field data in token

Thanks for your response.  Good idea.  Would the display tool work just the same?

Robb_Barrett
Marketo Employee

Re: Splitting field data in token

Don't know.  I actually never use Velocity.

Robb Barrett