Re: Custom Token Not Working Sometime

Eben_Saputra
Level 3

Custom Token Not Working Sometime

Hi there,

We personalize our email footer based on the Clinic ID of patient

The way we do this is by implementing a Global token (called my.global) as storage for information

Then we use Clinic ID as lookup value to get other data

This is a snippet of the value that we have

My.Global

","latitude":51.112309,"Longitude":-114.212415,"GetDirections":"www.google.com/maps/dir/Lifemark Crowchild Twin Arena+Crowchild Twin Arenas+Calgary+Alberta+T3L 1L4"},"313656":{"ClinicId":10159,"LPSClinicId":313656,"OfficialName":"Lifemark Sport - Canada Games Centre","Address1":"Suite 182","City":"Halifax","Province":"Nova Scotia","PostalCode":"B3S 0E2","Telephone":"(902) 404-3888","Email":"info.cgc@lifemark.ca","ParkingAndTransportation":"The clinic is wheelchair accessible. The newly expanded parking lot provides extensive free parking. If you have an injury or want to prevent future injuries, please call us now to schedule an appointment.

Now here comes the problem.

Only some of the token works

Clinic Name token never works

Clinic Name

Token Code

#set($clinicID = ${lead.ClinicID})

##if clinic id found

#if($clinics.Map.get($clinicID))

$clinics.Map.get($clinicID).OfficialName

#end

But Clinic Address always work

Clinic Address

Token Code

#set($clinicID = ${lead.ClinicID})

##if clinic id found

#if($clinics.Map.get($clinicID))

$clinics.Map.get($clinicID).Address1

#end

We actually used this technique before for other email journey and it was working without problem

Any thoughts why this doesn't work?

My.Global
","latitude":51.112309,"Longitude":-114.212415,"GetDirections":"www.google.com/maps/dir/Lifemark Crowchild Twin Arena+Crowchild Twin Arenas+Calgary+Alberta+T3L 1L4"},"313656":{"ClinicId":10159,"LPSClinicId":313656,"OfficialName":"Lifemark Sport - Canada Games Centre","Address1":"Suite 182","City":"Halifax","Province":"Nova Scotia","PostalCode":"B3S 0E2","Telephone":"(902) 404-3888","Email":"info.cgc@lifemark.ca","ParkingAndTransportation":"The clinic is wheelchair accessible. The newly expanded parking lot provides extensive free parking. If you have an injury or want to prevent future injuries, please call us now to schedule an appointment.

Clinic Name#set($clinicID = ${lead.ClinicID})##if clinic id found#if($clinics.Map.get($clinicID))$clinics.Map.get($clinicID).OfficialName#end
Clinic Address#set($clinicID = ${lead.ClinicID})##if clinic id found#if($clinics.Map.get($clinicID))$clinics.Map.get($clinicID).Address1#end

Tags (1)
10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token Not Working Sometime

Please go back in and highlight the code so it's readable.

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

Also, you shouldn't use ${formal} references in #set statements, use $simple to avoid syntax errors.

While you haven't published enough of your code, if this is the definition of $clinics:

#set( $clinics = {

"Map" : {

"313656" : {

"ClinicId" : 10159,

"LPSClinicId" : 313656,

"OfficialName" : "Lifemark Sport - Canada Games Centre",

"Address1" : "Suite 182"

}

}

} )

And $lead.ClinicID is a String (not Integer) with the value "313656" then there's no reason that both properties will not be found:

#set($clinicID = $lead.ClinicID)

#if($clinics.Map.get($clinicID))

$clinics.Map.get($clinicID).OfficialName

#end

#if($clinics.Map.get($clinicID))

$clinics.Map.get($clinicID).Address1

#end

Eben_Saputra
Level 3

Re: Custom Token Not Working Sometime

I tried putting erasing {} but it doesn't solve the problem.

Actually it was never a problem

Question : Is there a certain formatting condition that might cause token value to not be summoned?

Typically when using custom token, the display will be empty only if there is no data to display (or coding error, but we rule that out)

But in my case, when I use blank template ​the token will show up just fine

When I use this custom email template, then value stops showing for ClinicName

Newsletter - Google Docs

What is also curious, if I put this token side by side with other token, suddenly both token shows value

I suspect there might be some Marketo bug, so I

1. Clone to another campaign that has similar global token

2. Copy and use another token

3. Delete the email and copy new one

But same thing happens. The blanks shows value, but not the template.

Pretty much at wit's end here

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token Not Working Sometime

I tried putting erasing {} but it doesn't solve the problem.

Didn't say it was the cause in this case, but formal references cause syntax errors soon as you chain methods, which is why they should be avoided.

#set( $something = $reference.toUpperCase() ) ## no error

#set( $something = ${reference}.toUpperCase() ) ## error

When I use this custom email template, then value stops showing for ClinicName

Newsletter - Google Docs

What is also curious, if I put this token side by side with other token, suddenly both token shows value

Hmm... doesn't make much sense.

Are you including the tokens in exactly the same order in both cases (doesn't look like it from the links)?


What about in a plain-text email? Are you positive there isn't an HTML structural error that's causing something to be hidden (but in fact output in the HTML)?

Eben_Saputra
Level 3

Re: Custom Token Not Working Sometime

Oh man, you wouldn't believe what I found

Turns out one of the velocity token is "acting out"

There is this one token called City Token, that I use to summon City Value

The code is like every other token that I use so far

(sorry I don't see flair option here)

#set($clinicID = $lead.clinicID)

##if clinic id found

#if($clinics.Map.get($clinicID))

$clinics.Map.get($clinicID).City,

#end

However,

Any velocity token placed before this city token will not show value

If I delete this token, all velocity token will disappear

My solution is to place the token at the very top of email

And it works!! So right now I only need to make said token blends into the email background

Have you heard / seen of similar situation? Any idea why this might happen?

I really want to avoid this kind of surprise in the future.

Oh yes I removed the {}

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token Not Working Sometime

Have you heard / seen of similar situation?

Nope, and I've written a lot of Velocity across 20 instances.

Any idea why this might happen?

One thing that comes to mind is you're (re)initializing $clinicId at the top of every script -- or at least you think you are. If the rest of those lines have an errant invisible/control character accidentally in there, then they wouldn't be successfully setting $clinicId. Hence the get() check will always fail, leading to empty output.

(Note I wouldn't say the tokens "disappear" if it's actually that they simply don't output anything. You have to debug more deeply to see if the #if condition is simply not being met.)

(sorry I don't see flair option here)

The syntax highlighter is in Advanced Editor.

https://s3.amazonaws.com/blog-images-teknkl-com/mktonation_adved.png

Eben_Saputra
Level 3

Re: Custom Token Not Working Sometime

I think the problem is ... Marketo bug?

From customer support, I had 2 Marketo engineer and a script expert working on this, and they didn't see any dependency issues, token issues, etc.

But when I create another test email but at different folder, it magically works.

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token Not Working Sometime

Let me know if you want to continue to work on it offline. I guess if you're saying it's just "evil folder syndrome" that's one thing, but I'd like to prove it for myself.

Eben_Saputra
Level 3

Re: Custom Token Not Working Sometime

Not right now, especially because we have other developments on the pipeline. But thanks for the help so far!

Mark_Price
Level 7

Re: Custom Token Not Working Sometime

Have you checked the folders / programs in question for an 'Overridden' token? that could potentially cause the 'evil folder syndrome' issue

mkto-overridden.png