SOLVED

Velocity script to vary the From Address based on segmentation

Go to solution
Patrick_Vincler
Level 2

Velocity script to vary the From Address based on segmentation

Hi everyone,

I've got a beans and bacon question for this amazing community here. The beans - segmentation. The bacon - Velocity scripting.

What I'm trying to do:

Use a token in the From Address field, to vary our sender email address. Do this by condition of segmentation that is referenced in the script token.

My testing methodology:

Purely by sending an email though the campaign. No test emails sends or previews.

What I've covered already:

Have ticked the check box in right hand panel for the variable. (Segmentation_Clubs_1003)

My Code:

#if($lead.Segmentation_Clubs_1003 == "Client1")

info@client1.com

#elseif($lead.Segmentation_Clubs_1003 == "Client2")

info@client2.com

#elseif($lead.Segmentation_Clubs_1003 == "Client3")

info@client3.com

#elseif($lead.Segmentation_Clubs_1003 == "Client4")

info@client4.com

#elseif($lead.Segmentation_Clubs_1003 == "Client5")

info@clent5.com

#elseif($lead.Segmentation_Clubs_1003 == "Client6")

info@client6.com

#elseif($lead.Segmentation_Clubs_1003 == "Clent7")

info@client7.com

#else

info@standard.com

#end

Results:

Email delivers but only displays the default from address (info@standard.com)

Any insight is much appreciated! Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script to vary the From Address based on segmentation

Do it the collection-first way, it's both clearer and shorter:

#set( $senderByClub = {

"Client1" : "info@client1.com",

"Client2" : "info@client2.com",

"Client3" : "info@client3.com",

"Client4" : "info@client4.com"

} )

#set( $defaultSender = "info@standard.com" )

${display.alt($senderByClub[$lead.Segmentation_Clubs_1003],$defaultSender)}

The way you're doing it isn't wrong per se (although the use of == can get you into trouble and I recommend .equals() instead). But use the code above and see if it still fails.

Also, pls highlight code using the Advanced Editor:

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script to vary the From Address based on segmentation

Do it the collection-first way, it's both clearer and shorter:

#set( $senderByClub = {

"Client1" : "info@client1.com",

"Client2" : "info@client2.com",

"Client3" : "info@client3.com",

"Client4" : "info@client4.com"

} )

#set( $defaultSender = "info@standard.com" )

${display.alt($senderByClub[$lead.Segmentation_Clubs_1003],$defaultSender)}

The way you're doing it isn't wrong per se (although the use of == can get you into trouble and I recommend .equals() instead). But use the code above and see if it still fails.

Also, pls highlight code using the Advanced Editor:

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

Patrick_Vincler
Level 2

Re: Velocity script to vary the From Address based on segmentation

I'm getting a soft bounce when using this method.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script to vary the From Address based on segmentation 

That's tested code (with a Seg from one of my instances) so that's surprising.

Output just the Segment value and see what happens.

Patrick_Vincler
Level 2

Re: Velocity script to vary the From Address based on segmentation

I removed the default values, and the output is the actual last line of code: $(display.alt($senderByClub[$lead.Segmentation_Clubs1003])}

With the default values, is its ${display.alt($senderByClub[$lead.Segmentation_Clubs_1003],$defaultSender)}

The code doesn't appear to be processing. Hmmm

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script to vary the From Address based on segmentation 

Like I said, show the output of the segment value only.

Showing VTL code doesn't mean it isn't processing. The raw code is also the expected output on a null value without the silencing (!) operator.

Patrick_Vincler
Level 2

Re: Velocity script to vary the From Address based on segmentation 

I was finally able to get success with the following iteration. How 'equals' was notated seems to have been the key to solving the issue. Thanks Sanford Whiteman​ for the tips! Much appreciated.

#if($lead.Segmentation_Clubs_1003.equals("Client1"))

info@client1.com

#elseif($lead.Segmentation_Clubs_1003.equals("Client2"))

info@client2.com

#elseif($lead.Segmentation_Clubs_1003.equals("Client3"))

info@client3.com

#else

info@standard.com

#end

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script to vary the From Address based on segmentation 

Good to hear, Patrick. == in VTL is much stranger than people realize.

Jay_Jiang
Level 10

Re: Velocity script to vary the From Address based on segmentation

Any reason why you wouldn't just use the built in Marketo dynamic content to change the email's from address?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script to vary the From Address based on segmentation 

One reason is that you have to redo the dynamic content for every email, but the Velocity token can be shared by all email assets.