SOLVED

Token for subscription preferences not working in automated email

Go to solution
Highlighted

Token for subscription preferences not working in automated email

I have a token {{my.longsubpref}} : 

#if($lead.cOVID19 == "1")
#set($subscription0 = "<li>COVID-19 Bi-Weekly Newsletter</li>")
#else
#set($subscription0 = "")
#end

#if($lead.Alcoholic_Drinks__c == "1")
#set($subscription1 = "<li>Alcoholic Drinks</li>")
#else
#set($subscription1 = "")
#end

#if($lead.Apparel__c == "1")
#set($subscription2 = "<li>Apparel</li>")
#else
#set($subscription2 = "")
#end

#if($lead.Automotive__c == "1")
#set($subscription3 = "<li>Automotive</li>")
#else
#set($subscription3 = "")
#end

#if($lead.Beauty_Personal_Care__c == "1")
#set($subscription4 = "<li>Beauty & Personal Care</li>")
#else
#set($subscription4 = "")
#end

#if($lead.cannabis == "1")
#set($subscription5 = "<li>Cannabis</li>")
#else
#set($subscription5 = "")
#end

#if($lead.consumers == "1")
#set($subscription6 = "<li>Consumer Trends</li>")
#else
#set($subscription6 = "") 
#end

#if($lead.Consumer_Appliances__c == "1")
#set($subscription7 = "<li>Consumer Appliances</li>")
#else
#set($subscription7 = "")
#end

#if($lead.Consumer_Electronics__c == "1")
#set($subscription8 = "<li>Consumer Electronics</li>")
#else
#set($subscription8 = "")
#end

#if($lead.Consumer_Finance__c == "1")
#set($subscription9 = "<li>Consumer Finance</li>")
#else
#set($subscription9 = "")
#end

#if($lead.Consumer_Foodservice__c == "1")
#set($subscription10 = "<li>Consumer Foodservice</li>")
#else
#set($subscription10 = "")
#end

#if($lead.Consumer_Health__c == "1")
#set($subscription11 = "<li>Consumer Health</li>")
#else
#set($subscription11 = "")
#end

#if($lead.digcom == "1")
#set($subscription12 = "<li>Digital Commerce</li>")
#else
#set($subscription12 = "")
#end

#if($lead.economies == "1")
#set($subscription13 = "<li>Economic Trends</li>")
#else
#set($subscription13 = "")
#end

#if($lead.Eyewear__c == "1")
#set($subscription14 = "<li>Eyewear</li>")
#else
#set($subscription14 = "")
#end

#if($lead.Fresh_Food__c == "1")
#set($subscription15 = "<li>Fresh Food</li>")
#else
#set($subscription15 = "")
#end

#if($lead.Health_Wellness__c == "1")
#set($subscription16 = "<li>Health and Wellness</li>")
#else
#set($subscription16 = "")
#end

#if($lead.Home_Garden__c == "1")
#set($subscription17 = "<li>Home and Garden</li>")
#else
#set($subscription17 = "")
#end

#if($lead.Home_Care__c == "1")
#set($subscription18 = "<li>Home Care</li>")
#else
#set($subscription18 = "")
#end

#if($lead.Hot_Drinks__c == "1")
#set($subscription19 = "<li>Hot Drinks</li>")
#else
#set($subscription19 = "")
#end

#if($lead.Industrial__c == "1")
#set($subscription20 = "<li>Industrial</li>")
#else
#set($subscription20 = "")
#end

#if($lead.Ingredients__c == "1")
#set($subscription21 = "<li>Ingreients</li>")
#else
#set($subscription21 = "")
#end

#if($lead.Luxury_Goods__c == "1")
#set($subscription22 = "<li>Luxury Goods</li>")
#else
#set($subscription22 = "")
#end

#if($lead.Nutrition__c == "1")
#set($subscription23 = "<li>Nutrition</li>")
#else
#set($subscription23 = "")
#end

#if($lead.Packaged_Food__c == "1")
#set($subscription24 = "<li>Packaged Foods</li>")
#else
#set($subscription24 = "")
#end

#if($lead.Packaging__c == "1")
#set($subscription25 = "<li>Packaging</li>")
#else
#set($subscription25 = "")
#end

#if($lead.Personal_Accessories__c == "1")
#set($subscription26 = "<li>Personal Accessories</li>")
#else
#set($subscription26 = "")
#end

#if($lead.Pet_Care__c == "1")
#set($subscription27 = "<li>Pet Care</li>")
#else
#set($subscription27 = "")
#end

#if($lead.Retailing__c == "1")
#set($subscription28 = "<li>Retailing</li>")
#else
#set($subscription28 = "")
#end

#if($lead.Soft_Drinks__c == "1")
#set($subscription29 = "<li>Soft Drinks</li>")
#else
#set($subscription29 = "")
#end

#if($lead.sports == "1")
#set($subscription30 = "<li>Sports</li>")
#else
#set($subscription30 = "")
#end

#if($lead.sustainability == "1")
#set($subscription31 = "<li>Sustainability</li>")
#else
#set($subscription31 = "")
#end

#if($lead.Tissue_Hygiene__c == "1")
#set($subscription32 = "<li>Tissue and Hygiene</li>")
#else
#set($subscription32 = "")
#end

#if($lead.Tobacco__c == "1")
#set($subscription33 = "<li>Tobacco</li>")
#else
#set($subscription33 = "")
#end

#if($lead.Toys_Games__c == "1")
#set($subscription34 = "<li>Toys and Games</li>")
#else
#set($subscription34 = "")
#end

#if($lead.Travel_Tourism__c == "1")
#set($subscription35 = "<li>Travel and Tourism</li>")
#else
#set($subscription35 = "")
#end

#if($lead.africa == "1")
#set($subscription36 = "<li>Africa</li>")
#else
#set($subscription36 = "")
#end

#if($lead.lATAM == "1")
#set($subscription37 = "<li>Latin America</li>")
#else
#set($subscription37 = "")
#end

#if($lead.asiaPacific == "1")
#set($subscription38 = "<li>Asia Pacific</li>")
#else
#set($subscription38 = "")
#end

#if($lead.northAmerica == "1")
#set($subscription39 = "<li>North America</li>")
#else
#set($subscription39 = "")
#end

#if($lead.australia == "1")
#set($subscription40 = "<li>Australasia</li>")
#else
#set($subscription40 = "")
#end

#if($lead.westernEurope == "1")
#set($subscription41 = "<li>Western Europe</li>")
#else
#set($subscription41 = "")
#end

#if($lead.easternEurope == "1")
#set($subscription42 = "<li>Eastern Europe</li>")
#else
#set($subscription42 = "")
#end

<ul>
${subscription0}
${subscription1}
${subscription2}
${subscription3}
${subscription4}
${subscription5}
${subscription6}
${subscription7}
${subscription8}
${subscription9}
${subscription10}
${subscription11}
${subscription12}
${subscription13}
${subscription14}
${subscription15}
${subscription16}
${subscription17}
${subscription18}
${subscription20}
${subscription21}
${subscription22}
${subscription23}
${subscription24}
${subscription25}
${subscription26}
${subscription27}
${subscription28}
${subscription29}
${subscription30}
${subscription31}
${subscription32}
${subscription33}
${subscription34}
${subscription35}
${subscription36}
${subscription37}
${subscription38}
${subscription39}
${subscription40}
${subscription41}
${subscription42}
</ul>

 

When someone changes there subscription preferences they automatically get an email. Every option is working correctly except for the first one $subscription0 which is being used for COVID-19. When the corresponding COVID checkbox is checked and the subscription preferences are saved it never shows in the email. I can't figure out why it's only this particular one that isn't working, while the other options show correctly in an email based on whether it is checked or not checked in the form. Any ideas why this is happening? 

1 ACCEPTED SOLUTION

Accepted Solutions
Level 10 - Community Moderator

Re: Token for subscription preferences not working in automated email

No particular reason that wouldn't work, if the lead field's Velocity name is actually cOVID19 (case-sensitive) and you have it checked off in the tree on the right-hand-side of Script Editor.

 

But I find this kind of code really prone to error due to typos — it doesn't follow the DRY (Don't Repeat Yourself) principle.  You should try to use a collection-centric design, like so:

#set( $subscriptionFriendlyMap = {
  "cOVID19" : "COVID-19 Bi-Weekly Newsletter",
  "Alcoholic_Drinks__c" : "Alcoholic Drinks",
  "Apparel__c" : "Apparel",
  "Automotive__c" : "Automotive"
} )
#foreach( $subscription in $subscriptionFriendlyMap.entrySet() )
#if( $lead[$subscription.getKey()].equals("1") )
<li>$subscription.getValue()</li>
#end
#end

 

View solution in original post

1 REPLY 1
Level 10 - Community Moderator

Re: Token for subscription preferences not working in automated email

No particular reason that wouldn't work, if the lead field's Velocity name is actually cOVID19 (case-sensitive) and you have it checked off in the tree on the right-hand-side of Script Editor.

 

But I find this kind of code really prone to error due to typos — it doesn't follow the DRY (Don't Repeat Yourself) principle.  You should try to use a collection-centric design, like so:

#set( $subscriptionFriendlyMap = {
  "cOVID19" : "COVID-19 Bi-Weekly Newsletter",
  "Alcoholic_Drinks__c" : "Alcoholic Drinks",
  "Apparel__c" : "Apparel",
  "Automotive__c" : "Automotive"
} )
#foreach( $subscription in $subscriptionFriendlyMap.entrySet() )
#if( $lead[$subscription.getKey()].equals("1") )
<li>$subscription.getValue()</li>
#end
#end

 

View solution in original post