SOLVED

Re: Trimming characters off a token in an email script

Go to solution
Jason_Hamilton1
Level 8 - Champion Alumni

Trimming characters off a token in an email script

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

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Trimming characters off a token in an email script

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

View solution in original post

15 REPLIES 15
Kenny_Elkington
Marketo Employee

Re: Trimming characters off a token in an email script

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

Jason_Hamilton1
Level 8 - Champion Alumni

Re: Trimming characters off a token in an email script

Field type is string

Value would look something like this

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

Justin_Cooperm2
Level 10

Re: Trimming characters off a token in an email script

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
Level 8 - Champion Alumni

Re: Trimming characters off a token in an email script

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

Jason_Hamilton1
Level 8 - Champion Alumni

Re: Trimming characters off a token in an email script

Any other Ideas guys?

Anonymous
Not applicable

Re: Trimming characters off a token in an email script

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
Level 8 - Champion Alumni

Re: Trimming characters off a token in an email script

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

Anonymous
Not applicable

Re: Trimming characters off a token in an email script

Interesting. Sorry I am a bit late to reply.

If it helps, we can do a join.me session. I'd love to be able to help if I can.

Please suggest a couple of times coming week.

I am reachable at Rajesh@BrightAspects.com

Rajesh

Jason_Hamilton1
Level 8 - Champion Alumni

Re: Trimming characters off a token in an email script

Sent you an email