Splitting field data in token | Community
Skip to main content
Level 3
June 15, 2016
Question

Splitting field data in token

  • June 15, 2016
  • 4 replies
  • 4303 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

Level 3
June 15, 2016

Right now I have:

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

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

$repfullname[0]

Returns: $repfullname[0]

June 15, 2016

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

Level 3
June 15, 2016

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 2
June 15, 2016

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

Level 3
June 16, 2016

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.

July 9, 2016

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
Level 10
June 15, 2016

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
Level 3
June 16, 2016

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

Robb_Barrett
Level 10
June 16, 2016

Don't know.  I actually never use Velocity.

Robb Barrett