Hello Marketo Community,
I’m running into an issue while trying to populate a custom lead field in Marketo with data from an Opportunity field, and I’m hoping to get some insights or advice from those who may have encountered similar challenges.
What I’m Trying to Achieve:
I’m working on a campaign where I need to copy the nha_wlreapply_link (a URL) from the Opportunity object into a custom lead field called Waiting List Notification - Link Key Value. My goal is to make this data available on the lead record so that I can easily use it in emails and other assets.
Approach Taken So Far:
Velocity Script Token:
#if($OpportunityList.size() > 0)
${OpportunityList.get(0).nha_wlreapply_link}
#else
No link available
#end
Change Data Value Flow Step:
Issue:
Instead of storing the resolved URL, the custom field Waiting List Notification - Link Key Value ends up with a value that includes the whole script and its associated metadata in JSON format.
What I’ve Learned:
I now understand that Velocity script tokens may not work as intended in flow steps like "Change Data Value" because Marketo might not process them correctly in this context.
Question to the Community:
Has anyone successfully populated a custom lead field from an Opportunity field using a method that works in a flow step, particularly in cases where the Opportunity field isn’t directly available as a token? Is there a workaround or best practice that can achieve this without resorting to Velocity scripts in flow steps?
Any advice, tips, or alternative approaches would be greatly appreciated!
Thank you in advance for your help!
Solved! Go to Solution.
If you can’t see them on the tab, then they’re not in Marketo and nothing you can do can make them accessible in Velocity, let alone in a lead field.
Looks to me like something is severely broken with your Opportunity sync.
I now understand that Velocity script tokens may not work as intended in flow steps like "Change Data Value" because Marketo might not process them correctly in this context.
Well, they do work “as intended” because Email Script/Velocity {{my.tokens}} are intended for use only in emails. There’s never been any claim that they’d be executed in Change Data Value steps.
Has anyone successfully populated a custom lead field from an Opportunity field using a method that works in a flow step, particularly in cases where the Opportunity field isn’t directly available as a token?
Let’s step back for a moment. Opportunities have a many:one relationship with people. It would never make sense to have a single Opportunity arbitrarily publish {{opportunity.field}} tokens. (The most important Opportunity or most recently updated Opportunity, perhaps, but not just “that person’s Opportunity” since there’s no such thing.)
I’m working on a campaign where I need to copy the nha_wlreapply_link (a URL) from the Opportunity object into a custom lead field called Waiting List Notification - Link Key Value. My goal is to make this data available on the lead record so that I can easily use it in emails and other assets.
Why do you need (emphasis on need) to copy it instead of just outputting it from the {{my.token}}? What are the “other assets” in question?
I’m working on a campaign where I need to copy the nha_wlreapply_link (a URL) from the Opportunity object into a custom lead field called Waiting List Notification - Link Key Value. My goal is to make this data available on the lead record so that I can easily use it in emails and other assets.
Why do you need (emphasis on need) to copy it instead of just outputting it from the {{my.token}}? What are the “other assets” in question?
____
To address this question, I don't need to necessarily. The idea was a product of trying to find a workaround because my Manger and I have been having the hardest time getting a successful output from the {{my.token}}. I'll list a few of the variations we've used thus far and I'll let you tell me what we might be doing wrong. I should note that I am leveraging ChatGPT to help me write these tokens as I am 8 months into my Marketo learning. I am very aware that ChatGPT leaves a lot to be desired in this area. I only need the link to be accessible in the email. However we get there is fine by me.
These are scripts we've attempted and in the order we've attempted them:
## Fetching the complete reapply link from the lead's field
#set( $reapplyLink = ${opportunityList.get(0).nha_wlreapply_link} )
## Output the reapply link for use in the email
${reapplyLink}
#set($opportunityList = $OpportunityList)
#if($opportunityList.size() > 0)
${opportunityList.get(0).nha_wlreapply_link}
#else
<!-- Default value or message if the opportunity list is empty -->
No link available.
#end
#set($opportunityList = $OpportunityList)
#set($accountEmail = ${lead.EmailAddress}) ## Assuming the email address is stored in the lead or account record
#foreach($opportunity in $opportunityList)
#if($opportunity.EmailAddress == $accountEmail) ## Assuming the opportunity has an EmailAddress field
${opportunity.nha_wlreapply_link}
#break
#end
#end
## Optional default message if no matching opportunity is found
#if(!$foreach.hasNext())
No matching opportunity found or no link available.
#end
#set($opportunityList = $OpportunityList)
#set($accountEmail = ${lead.EmailAddress})
#if($opportunityList && $opportunityList.size() > 0)
#foreach($opportunity in $opportunityList)
#if($opportunity.EmailAddress == $accountEmail)
${opportunity.nha_wlreapply_link}
#break
#end
#end
#if(!$foreach.hasNext())
No matching opportunity found or no link available.
#end
#else
No opportunities available.
#end
As you note, that generated code leaves a lot to be desired. Some is awful, some is getting close, none is tight.
The starting point is seeing the “shape” of your raw data, without trying to parse it in any way.
Create a {{my.token}} with only this line:
${OpportunityList}
Of course check off the required field on the right-hand side of Script Editor as well.
Post the output from preview-by-list or from a real email (not sample) sent to a person.
As you note, that generated code leaves a lot to be desired. Some is awful, some is getting close, none is tight.
The starting point is seeing the “shape” of your raw data, without trying to parse it in any way.
Create a {{my.token}} with only this line:
${OpportunityList}
Of course check off the required field on the right-hand side of Script Editor as well.
Post the output from preview-by-list or from a real email (not sample) sent to a person.
Thanks for the suggestion, this is what populated in the email I received.
Can you show a screenshot of Script Editor where you’ve checked off the field?
Of Course, here it is:
How are you determining that the test person has at least 1 Opportunity?
We're working with our Guardian CRM team on this and they sent over a test lead with the information. When I open the lead activity info in Marketo Sandbox, I can see the opportunity info written in the notes of the activity ID.