SOLVED

How to get a token script to display information from Opportunity Object?

Go to solution
Alex_Bridges3
Level 2

How to get a token script to display information from Opportunity Object?

Hi all,

I'm trying to create custom token scripts based on items on the opportunity object. However, when I follow the directions here, Create an Email Script Token - Marketo Docs - Product Documentation,​ it doesn't render.

For example, I create a custom token. I call it my.ExampleTokenA. I need it to show the value for Example Opportunity Item A from the Opportunity Object.

When I edit the token, I go to the Opportunity object list, and pick Example Opportunity Item A from the list, and drag it over. So now in my script editor, I see ${OpportunityList.get(0).Example_Opportunity_Item_A}.

However, when I go to test my token, instead of seeing that value, I see ${OpportunityList.get(0).Example_Opportunity_Item_A}. What do I need to do to get it to display the value? No additional formatting is needed; I just need it to display what's there.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to get a token script to display information from Opportunity Object?

Ok, I did more digging on the SFDC side and the stuff is going over okay, there's just not data in those particular fields yet.

Ah, yes, so not a Velocity thing.

So next question - if a field is null, how can I get it to display "---", instead of displaying the script?

$display.alt($OpportunityList[0].Example_Opportunity_Item_A, "---")

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: How to get a token script to display information from Opportunity Object?

You must test Velocity tokens using preview-by-list with a static list or via a real email (not sample).

Also note your code here is using the first Oppty in the list. That may not be practical.

Alex_Bridges3
Level 2

Re: How to get a token script to display information from Opportunity Object?

I set the test up using preview-by-list, but I'm still getting the token script spit back to me (though, oddly, a few don't show any value at all). Any ideas as to what might be going on here?

As far as I know, the first in the list is acceptable at this point; I think the main concern is getting a value to show up instead of velocity script right now.

Thanks!

SanfordWhiteman
Level 10 - Community Moderator

Re: How to get a token script to display information from Opportunity Object?

I assume you've made sure that Example_Opportunity_Item_A ​is still checked in the list on the right-hand-side? (Sometimes they get unchecked unexpectedly.)

The way to start lower-level debugging is to include

$display.list( $OpportunityList, "\u000a" )

in the token and look in the Text version of the email. (Using the Text instead of HTML version ensures that no output is ever parsed and swallowed up by your browser.)

Also, can you show some screenshots establishing that the people in your test static list have at least one Opportunity?

Alex_Bridges3
Level 2

Re: How to get a token script to display information from Opportunity Object?

I'm using test leads with the criteria of "has opportunity" is "true," then added to a static list to test off of. Unfortunately, I can't share screen shots, due to security protocol here.

I inserted the line of code into my first token, and noticed that it pulls up the list of custom tokens I've made for the program. The values for every field in the list is "null," which implies to me it may be a data sync issue, instead of an issue with the token script itself. (I did find there were a couple that had gotten unchecked and was able to re-check those, thanks for the tip!)

Any thoughts on next steps for debugging? Or have I officially hit the wall of "not a token script issue"?

Thanks for all your help!

Alex_Bridges3
Level 2

Re: How to get a token script to display information from Opportunity Object?

Ok, I did more digging on the SFDC side and the stuff is going over okay, there's just not data in those particular fields yet.

So next question - if a field is null, how can I get it to display "---", instead of displaying the script?

SanfordWhiteman
Level 10 - Community Moderator

Re: How to get a token script to display information from Opportunity Object?

Ok, I did more digging on the SFDC side and the stuff is going over okay, there's just not data in those particular fields yet.

Ah, yes, so not a Velocity thing.

So next question - if a field is null, how can I get it to display "---", instead of displaying the script?

$display.alt($OpportunityList[0].Example_Opportunity_Item_A, "---")

Alex_Bridges3
Level 2

Re: How to get a token script to display information from Opportunity Object?

Excellent! All is working as it should.

There's a second component to the issue I'm having, and let me know if this merits closing this thread down to start a new one.

I'm creating formula fields to house these tokens, along with some regular lead tokens. Reason being that there's a 40 token limit on emails, and the emails we need to send out would need to contain more than 40 tokens. The formula fields render fine when I'm using the lead tokens, but there's a lot of tokens that need to be based on the opportunity object. Now that I've created custom tokens for the items based on the opportunity object, I figured I could put those into the formula fields, and that they'd render as long as the email calling those tokens was based within the program using the custom tokens. The custom tokens went into the field as {{my.ExampleToken:default=---}}. However, I'm noticing that, when previewing off the list, they're rendering as {{my.ExampleToken}}; no default value attached.

Is there a reason that the formula fields aren't showing the custom tokens as they should?

SanfordWhiteman
Level 10 - Community Moderator

Re: How to get a token script to display information from Opportunity Object?

There's a second component to the issue I'm having, and let me know if this merits closing this thread down to start a new one.

It would probably be better in another thread, but you might not want to bother because what you're describing (if I'm reading it correctly) can't be done.

You can't include {{my.tokens}} in formula fields.

Alex_Bridges3
Level 2

Re: How to get a token script to display information from Opportunity Object?

Got it. What about creating a custom token in place of the formula field? In this case, the content of the formula field is a table, containing other tokens. Could I script a token to house a table, inclusive of other tokens + oppty fields?

(I'll create another thread for this question, but putting it here first just in case.)