SOLVED

Velocity Script Using Custom Object Not Appending When Email Is Sent

Go to solution
Raquel_Babb
Level 2

Velocity Script Using Custom Object Not Appending When Email Is Sent

Hello,

We are having trouble with an email using velocity script to display a field within a custom object.  The field in the custom object contains a UUID which is needed to append to a link for a campaign we'll be running. We're using the velocity script token in the email link listed below.  It appears as it's working when we send the email; however, when clicked, the email link takes us to a page stating an invitation is requested (used when there is no UUID matched to the database).  But when opening the email in the browser and clicking the link, it then works and processes the page with the proper message. Why won't the link append the Program UID field as anticipated?

Link in Email: https://{{my.Email - CTA3_URL}}?offer=1&invitation={{my.Campaign UID}}

Velocity Script Token {{my.Campaign UID}} Details: ${cashBackVisa_cList.get(0).ProgramUID}

Field Name in Custom Object: Program UID

URL Shown from Email (random test): https://www.example.com/promotion?offer=1&invitation=${cashBackVisa_cList.get(0).ProgramUID}

URL Shown When the Same Email is Viewed in the Browser: https://www.example.com/promotion?offer=1&invitation=0736c113-669b-4043-9081-4a814eda08b8

(For security sake, I've made the beginning of the link an example)

There could be members who have more than one Program ID within this custom object.  Not sure if this means anything when using velocity script.

Sanford Whiteman​ would you be able to help at all?

Thanks,

Raquel

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

You're using a real email, not a sample?

If it's a real email, have you tried recreating the token?  I wonder if the token's link to the CO object has become corrupt (even if it's checked off in the tree in Script Editor). This happens sometimes.

Is there any way we can populate a custom lead field with the Program UID data that's in the custom object?

Not without some extremely complex development, and if what you're doing right now isn't working, that development couldn't work either.

View solution in original post

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

There could be members who have more than one Program ID within this custom object. Not sure if this means anything when using velocity script.

It certainly does... when you use $list.get(0) -- or its clearer alternative, $list[0] -- you're getting the first record in the list.  So you're using that first record's ProgramUID field, every time.

But that in itself isn't your problem. I suspect you're dealing with the different order-of-operations of Web View vs. Emails with regard to Velocity (which can be very confusing).

Try adding an empty check around the list (which you should always do anyway) and outputting this entire <a> from Velocity:

#if( !$cashBackVisa_cList.isEmpty() )

<a href="https://www.example.com?offer=1&invitation=${cashBackVisa_cList[0].ProgramUID}">Click here</a>

#end

Raquel_Babb
Level 2

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

Hi Sanford Whiteman​,

Thanks for your quick response!  I tried this and it seems to be having the same issue - once clicked, the email link doesn't work, but when clicking the email in the browser it processes the page with the proper message.  Do you know why this is happening?

Email Click: https://www.example.com/promotion?offer=1&invitation=${cashBackVisa_cList.get(0).ProgramUID}&mkt_tok...

Browser Click: https://www.example.com/promotion?offer=1&invitation=0736c113-669b-4043-9081-4a814eda08b8

Is there any way we can populate a custom lead field with the Program UID data that's in the custom object?  Of course, assuming we're going to use the first record's Program UID if members have more than one, and then include that lead field in the email link instead.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

You're using a real email, not a sample?

If it's a real email, have you tried recreating the token?  I wonder if the token's link to the CO object has become corrupt (even if it's checked off in the tree in Script Editor). This happens sometimes.

Is there any way we can populate a custom lead field with the Program UID data that's in the custom object?

Not without some extremely complex development, and if what you're doing right now isn't working, that development couldn't work either.

Raquel_Babb
Level 2

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

Sanford Whiteman​ IT WORKS!  I was using a sample email with a lead's information.  I've since recreated the velocity script token and added some styling to increase the font, make the link white, etc. ...and it works!  Thank you so much!

As for pulling in the CO data into a lead field, that's highly disappointing but understandable. I wish Marketo made it easier to understand velocity scripting and accessing custom object data.  Again, thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

OK, great. Yes, you can't use Samples to test Velocity unless the content is generated entirely within Velocity (i.e. no references to fields in the database... only local variables that you #set() in a Velocity token).

Raquel_Babb
Level 2

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

Sanford Whiteman​ Ah, that is understandable.  Could you tell me what the stipulations are using the velocity script token to link an image?  I tried doing this but kept getting a target="_blank"></a> text showing up.  I tried recreating but not sure I did it correctly.  Should it work using:

#if( !$cashBackVisa_cList.isEmpty() ) 

<a href="https://www.example.com/promotion?offer=1&invitation=${cashBackVisa_cList[0].ProgramUID}"></a>

#end

I tried a couple other ways, but none seemed to work.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script Using Custom Object Not Appending When Email Is Sent

There's no image in there, though.

Also please highlight code using the Advanced Editor's Syntax Highlighter:

pastedImage_2.png