SOLVED

Re: Help with Populating Custom Field from Opportunity

Go to solution
solson2
Level 3

Help with Populating Custom Field from Opportunity

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:

    • I created a Velocity script token to pull the nha_wlreapply_link from the Opportunity object using the following script:

      Velocity Script Token:

 

#if($OpportunityList.size() > 0)
    ${OpportunityList.get(0).nha_wlreapply_link}
#else
    No link available
#end

 

 

  • Change Data Value Flow Step:

    • I attempted to use this Velocity script token in a "Change Data Value" flow step to populate the Waiting List Notification - Link Key Value field, but it resulted in the field being populated with the entire script as a JSON object rather than the resolved URL.

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!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Populating Custom Field from Opportunity

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.

View solution in original post

12 REPLIES 12
SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Populating Custom Field from Opportunity


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?

solson2
Level 3

Re: Help with Populating Custom Field from Opportunity

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

 

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Populating Custom Field from Opportunity

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.

solson2
Level 3

Re: Help with Populating Custom Field from Opportunity

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. 

 

Screenshot 2024-08-15 at 2.58.45 PM.png

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Populating Custom Field from Opportunity

Can you show a screenshot of Script Editor where you’ve checked off the field?

solson2
Level 3

Re: Help with Populating Custom Field from Opportunity

Of Course, here it is:

Screenshot 2024-08-15 at 3.24.58 PM.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Populating Custom Field from Opportunity

How are you determining that the test person has at least 1 Opportunity?

solson2
Level 3

Re: Help with Populating Custom Field from 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. 

Screenshot 2024-08-16 at 9.01.11 AM.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Help with Populating Custom Field from Opportunity

Can you see the record on the Opportunities tab?