SOLVED

Velocity Scripting - Dynamic content based on store list

Go to solution
jclayton
Level 1

Velocity Scripting - Dynamic content based on store list

I'm new to Marketo and Velocity scripting, so hopefully this is a dumb question with an easy answer.
 
I'd like to use Velocity to display dynamic content in an email based on a subscriber's Store Number. My current code is below. I'm having issues getting my "version one" to work. My "default" version works fine, though, so I'm assuming it's just a silly formatting error, except I've tried every combination of quotes and parenthesis I can think of. Anyone able to help me figure out what I've screwed up?
#set($store = $convert.toNumber($lead.storeNumber) )
#if($store == "106" || $store == "103" || $store == "330" || $store == "104" || $store == "100" || $store == "108" || $store == "102" || $store == "114" || $store == "107" || $store == "117" || $store == "115" || $store == "110" || $store == "112" || $store == "129" || $store == "124" || $store == "140" || $store == "123" || $store == "120" || $store == "135" || $store == "133" || $store == "116" || $store == "121" || $store == "128" || $store == "134" || $store == "132" || $store == "125" || $store == "122" || $store == "136" || $store == "160" || $store == "161" || $store == "151" || $store == "139" || $store == "148" || $store == "150" || $store == "156" || $store == "162" || $store == "141" || $store == "142" || $store == "147" || $store == "158" || $store == "154" || $store == "153" || $store == "159" || $store == "166" || $store == "164" || $store == "165" || $store == "163" || $store == "152" || $store == "301" || $store == "311" || $store == "307" || $store == "305" || $store == "308" || $store == "317" || $store == "320" || $store == "316" || $store == "310" || $store == "313" || $store == "312" || $store == "322" || $store == "319" || $store == "321" || $store == "329" || $store == "325" || $store == "8023" || $store == "8006" || $store == "8007" || $store == "8000" || $store == "8026" || $store == "8016" || $store == "8029" || $store == "8045" || $store == "8055" || $store == "8036" || $store == "8015")
here's version one!
#else
here's the default!
#end
1 ACCEPTED SOLUTION

Accepted Solutions
Jon_Wright
Level 3

Re: Velocity Scripting - Dynamic content based on store list

Firstly, make sure you have checked off your lead.storeNumber field from the tree on the right-hand side. But as Sanford says, and he's always right on these things, easier to use a list and see if it contains the value e.g.

 

#set($store = $lead.storeNumber )
#set($storeList = [ "100","102","103","104","106","107","108","110","112","114","115","116","117","120","121","12","123","124","125","128","129","132","133","134","135","136","139","140","141","142","147","48","150","151","152","153","154","156","158","159","160","161","162","163","164","165","166","301","305","307","308","310","311","312","313","316","317","319","320","321","322","325","329","330","8000","8006","8007","8015","8016","8023","8026","8029","8036","8045","8055"] )
#if($storeList.contains($store))
here's version one!
#else
here's the default!
#end

 

 

 

Note this is not converting the storeNumber to a Number, but if you need to do that you can use 

 

#set($store = $convert.toInteger($lead.storeNumber) )

 

 

and then your list of stores wouldn't contain the quotes. But $convert.toInteger will throw an error if the field doesn't contain a 'number'

 

FYI - Sanford's blog is a great resource for Velocity tips: https://blog.teknkl.com/tag/velocity/

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - Dynamic content based on store list

Oof. Please don't do it with all those conditions. Instead, create a list of the matchable values and then test if the list.contains() the current value.

Also, why are you converting the value to a Number, but then matching it to a String?



Jon_Wright
Level 3

Re: Velocity Scripting - Dynamic content based on store list

Firstly, make sure you have checked off your lead.storeNumber field from the tree on the right-hand side. But as Sanford says, and he's always right on these things, easier to use a list and see if it contains the value e.g.

 

#set($store = $lead.storeNumber )
#set($storeList = [ "100","102","103","104","106","107","108","110","112","114","115","116","117","120","121","12","123","124","125","128","129","132","133","134","135","136","139","140","141","142","147","48","150","151","152","153","154","156","158","159","160","161","162","163","164","165","166","301","305","307","308","310","311","312","313","316","317","319","320","321","322","325","329","330","8000","8006","8007","8015","8016","8023","8026","8029","8036","8045","8055"] )
#if($storeList.contains($store))
here's version one!
#else
here's the default!
#end

 

 

 

Note this is not converting the storeNumber to a Number, but if you need to do that you can use 

 

#set($store = $convert.toInteger($lead.storeNumber) )

 

 

and then your list of stores wouldn't contain the quotes. But $convert.toInteger will throw an error if the field doesn't contain a 'number'

 

FYI - Sanford's blog is a great resource for Velocity tips: https://blog.teknkl.com/tag/velocity/

 

View solution in original post

jclayton
Level 1

Re: Velocity Scripting - Dynamic content based on store list

Awesome! Thank you both for your help. I appreciate it.