Skip to main content
October 11, 2016
Question

email script token not working

  • October 11, 2016
  • 2 replies
  • 2991 views

Hi friends,

I'm writing a script token that removes the domain extension (like ".com" or ."org") of an email address before displaying the result whenever called from a flow.

It's not working. Perhaps I've done something wrong here. Please can anyone help?

set ($leadEmail=${lead.Email})   

set ($fiveLetterEnding = [".co.uk", ".co.jp", ".co.za"])

set ($fourLetterEnding = [".info", ".name", ".mobi"])

set ($threeLetterEnding = [".com", ".net", ".edu", ".gov", ".org", ".biz"])

set ($twoLetterEnding = [".fr", ".be"])

If ($leadEmail.matches("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$"))

  foreach ($fiveLetterEnding)

    if ($leadEmail.matches("^$fiveLetterEnding"))

    $leadEmail=$leadEmail.substring(0, 4)

    end

  end

  foreach ($fourLetterEnding)

    if ($leadEmail.matches("^$fourLetterEnding"))

    $leadEmail=$leadEmail.substring(0, 3)

    end

  end

  foreach($threeLetterEnding)

    if ($leadEmail.matches("^$threeLetterEnding"))

    $leadEmail=$leadEmail.substring(0, 2)

    end

  end

  foreach($twoLetterEnding)

    if ($leadEmail.matches("^$twoLetterEnding"))

    $leadEmail=$leadEmail.substring(0, 1)

    end

  end

 

end

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

2 replies

Grégoire_Miche2
Level 10
October 11, 2016

HI Kenneth,

what do you mean by:

"before displaying the result whenever called from a flow"

?

Velocity tokens only render in emails. If you were trying to use it as a new value in a flow step, for instance, it would not work.

-Greg

October 12, 2016

I'm very sorry for my late reply.

Actually, I wanted to build a simple campaign that assigns company names to leads that have no company data but have an email address with their company's official domain like "......@microsoft.com".

So the aim is to trim off "......@" and ".com" to have just "microsoft" and in the flow of this campaign, I plan to call an email script token like "my.companyName" so that I have Company Name = "my.companyName".

The script above was supposed to ronly remove ".com" from the email address but didn't work. Perhaps I am doing something wrong

SanfordWhiteman
Level 10
October 12, 2016

Actually, I wanted to build a simple campaign that assigns company names to leads that have no company data but have an email address with their company's official domain like "......@microsoft.com".

Email scripts can't update lead fields. They are used to display custom content in an emails, but they do not write content back to the database.

SanfordWhiteman
Level 10
October 11, 2016

Need more than "not working" -- actual behavior and errors.  And definitely note Greg's follow-up.

I'll say straight away that what you've pasted isn't valid Velocity (VTL) code, since the lines don't begin with '#'.  (The way you're doing the parsing is also way too verbose -- if you're hard-coding the small list of domains you care about, you only need one line to trim to trim all such values.)

October 12, 2016

Thanks Sanford, I think i'm still doing something wrongly. Please would you know any ways of making this code simpler and less verbose?