SOLVED

Nesting Tokens

Go to solution
Mx_Braze
Level 2

Nesting Tokens

I have a paragraph inside an email that needs to be altered depending on certain lead attributes. I created the following token that successfully changes which paragraph is displayed, however it doesn't fully work.

#if( ${lead.Layer__c}== "Base")
<p>Reach out to your recruiter {{lead.Lead Owner First Name:default=}} @ {{lead.Lead Owner Email Address:default=}}</p>
#else
<p>Nothing catching your eye? <a href="LINK">Click Here</a></p>

#end

 The problem is that the paragraph prints into the email like this:

"Reach out to your recruiter {{lead.Lead Owner First Name:default=}} @ {{lead.Lead Owner Email Address:default=}}"

 

How would I go about making those two bolded tokens actually print their respective values? I thought I could use the #set command at the start of the script token, but that doesn't work.

#set( $firstName== ${lead.Lead Owner First Name})
#set( $email== ${lead.Lead Owner Email Address})
#if( ${lead.Layer__c}== "Base")
<p>Reach out to your recruiter $firstName @ $email</p>
#else
<p>Nothing catching your eye? <a href="LINK">Click Here</a></p>

#end

 

Trying to preview my email with this token inside of it just breaks the preview window. Velocity Script is fairly new to me, so it's entirely possible I just didn't use the right syntax. Is it possible to do what I'm trying to do here?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Nesting Tokens

There’s no better place than here. (And most of that is cross-posted to the official Products blog.) I’m really the only one in the world learning/writing at length about Velocity-in-Marketo specifically.

 

The link you posted to Velocity 1.7 uses the same syntax as Marketo (and that’s the right version), not sure exactly what you mean there?

 

There reason you shouldn’t use == is it coerces the types of its operands to strings if the types don’t otherwise match. This can lead to wildly strange outcomes (in both directions, false negative and false positive). In contrast .equals() is strongly typed and doesn’t do anything magical.

View solution in original post

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Nesting Tokens

No need for any kind of "nesting". Those Person fields are all available in Velocity already. Just choose them from the tree.

Also, you shouldn't be using ${var} (formal references) here, just $var (simple refs). And don't use ==, use .equals().

Mx_Braze
Level 2

Re: Nesting Tokens

When you say, "choose them from the tree," I assume you mean this menu inside the script token editor right?

Mx_Braze_0-1743104374930.png

I've expanded every single option in there and I do not see the values I'm trying reference. I know they exist because if I just drop either one into an email, they populate normally. It's only when I try to include them inside a token that they stop working.

As for your other advice, I tried updating my if/then statement to follow the rules you gave me and it stopped working. It still worked after removing the brackets [#if( $lead.Layer__c.equals== "Base")] but it stopped working when I changed out == for .equals() [#if( $lead.Layer__c.equals(Base))]. 




SanfordWhiteman
Level 10 - Community Moderator

Re: Nesting Tokens

You didn’t supply your full token code so I can’t show you where you introduced a syntax error.

 

Under “Person”, fields like Sales Owner Email Address should be easily accessible.

SanfordWhiteman_0-1743105627477.png

 

 

Mx_Braze
Level 2

Re: Nesting Tokens

Got it. So that attribute should be in there and it isn't. I guess I'll get on Support's case about that.

Below is the whole token after I made the changes you suggested. I'm not expecting the "Lead Owner" stuff to work with this iteration, but at the very least I still expected the if/then statement to work.

#if( $lead.Layer__c.equals(Base))
<p>Reach out to your dedicated recruiter {{lead.Lead Owner First Name:default= }} @ {{lead.Lead Owner Email Address:default= }}</p>
#else

<p>Nothing catching your eyes? <a href="LINK">Click here</a>.</p>
#end

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Nesting Tokens

You still need quotes around string literals like "Base".

Mx_Braze
Level 2

Re: Nesting Tokens

Aaah, thanks for clarifying. That part of my code works now. I really wish there was more documentation about Velocity scripting inside of Marketo. I tried emailing Marketo Support for help and they basically told me they couldn't troubleshoot Velocity script tokens because it's just something they provide access to and not something they are trained on.

Can you point me towards any good sources of how to use Velocity, specifically as it works in Marketo? I tried looking at this guide from the creators, but it doesn't seem to use the same syntax. It doesn't even mention the ".equals()" notation that you suggested.

SanfordWhiteman
Level 10 - Community Moderator

Re: Nesting Tokens

There’s no better place than here. (And most of that is cross-posted to the official Products blog.) I’m really the only one in the world learning/writing at length about Velocity-in-Marketo specifically.

 

The link you posted to Velocity 1.7 uses the same syntax as Marketo (and that’s the right version), not sure exactly what you mean there?

 

There reason you shouldn’t use == is it coerces the types of its operands to strings if the types don’t otherwise match. This can lead to wildly strange outcomes (in both directions, false negative and false positive). In contrast .equals() is strongly typed and doesn’t do anything magical.