Trimming characters off a token in an email script | Community
Skip to main content
Jason_Hamilton1
New Participant
February 10, 2016
Solved

Trimming characters off a token in an email script

  • February 10, 2016
  • 4 replies
  • 4346 views

I am using an email script token and am trying to remove the last three chars from the token.

The problem I think I am having is that the code I am using to strip the three chars assumes the value of the token is a string but I assume it is not (its type however is set to string).

If I am correct with that assumption how do I convert the value to a string, or is there an alternate way to remove the three chars?

Here is the code I am using, I get an error when I try and send the email and it references the substring.

When I hardcode a value in it works fine

#set ($string = ${lead.cRCURL})

#set ($stringLength = $string.length() - 3)

#set ($string = $string.substring(0,$stringLength))

$string

Any help would be greatly appreciated.

Thanks,

Jason

Best answer by

Sent you an email


Hi Jason,

After our Join.me call to debug this issue, I spent some time testing / debugging it.

There was nothing wrong in what you were doing.

After I figured it out and got it to work, and only then, I remembered that I went through this same issue 8 months back.

There is a 'GOTCHA' when it comes to velocity script testing.

'Send sample email' is not a good way for testing velocity scripts. Even if we choose a 'lead' to test the email with velocity script against, it does not 'accurately' evaluate the velocity script. In other words, when you 'send sample email' with Velocity script, all the 'lead token' values in the velocity script are NULL.

And that's why we keep on getting errors. And it all works perfectly fine when we hard code data to test.

To test, simply create a test smart campaign and execute it to send the test email to yourself.

It will work just fine.

I am sending you the script and the test email where it worked soon.

Why?

I guess the send Sample Email does not 'invoke' some Marketo server component to actually render 'lead's data in Velocity script.

I do not claim to have all the 'internal' knowledge of Marketo here but this is based on what I have experienced.

Hope this helps

Rajesh

4 replies

Jason_Hamilton1
New Participant
February 23, 2016

One thing I will add, is that it still gives me an error when I try to approve my email, so my workaround is to remove the content of my token, approve the email, then add the token content back, not ideal but it works.

Thanks for the help Rajesh!

February 23, 2016

Glad that you made it to work.

Rajesh

Jason_Hamilton1
New Participant
February 11, 2016

Any other Ideas guys?

February 11, 2016

Hi Jason,

Not giving code here but steps that I would try to get to the bottom of the issue here. You probably must have tried these already. But mentioning if it can help nevertheless.

1> check for null
$!${lead.cRCURL}

2> check if it is set
#if($UtilMethods.isSet(${lead.cRCURL})

3> Hard code and test your code
#set ($string = "This is my test")

#set ($stringLength = $string.length() - 3)

#set ($string = $string.substring(0,$stringLength))

$string

And see if that prints ok

4> Print the 'unaltered string' first to confirm that the data is coming fine.
#set ($string = ${lead.cRCURL})
$string

#set ($stringLength = $string.length() - 3)

#set ($string = $string.substring(0,$stringLength))

$string


5> Are you sure to 'check' the check box on the RHS of the script token to 'enable' the object you are getting this variable from?
If not, the script gets null value even if in Marketo lead view you see data populated.

regards

Rajesh Talele

Jason_Hamilton1
New Participant
February 12, 2016

Hi Rajesh,

I have tried those things with no luck.

When I hard code it works fine, the box is checked, and if I include just the token in the email (not the script token, it works fine, so I know there is a value in the field.  Unfortunately I need to remove some chars from the string so I am using the script token to do so.

Jason

Justin_Cooperm2
New Participant
February 10, 2016

It most likely means that ${lead.cRCURL} was null for that lead, or something of the sort. You should always check if something is present before calling additional functions.

Jason_Hamilton1
New Participant
February 10, 2016

I only tested with one record and it is populated for that record

Kenny_Elkington
New Participant
February 10, 2016

What is the field type and a typical value from the cRCURL field?

Jason_Hamilton1
New Participant
February 10, 2016

Field type is string

Value would look something like this

Imaging%3bnursing%3bpharmacy%3btherapy%3b