SOLVED

Re: Velocity Email Script Token for Checkboxes

Go to solution
norahpost
Level 1

Velocity Email Script Token for Checkboxes

I am trying to create an email script token for a program with the following workflow:

 

-A checkbox is selected in the Exosome Brochure Downloads field on form FM 01

-That selection is inserted into the email that sends out after the form fill

 

I would like the customer to be able to select multiple check boxes and have only those selections appear in the email. For example, if the customer selects B1, only B1 will show up in the email. But if they select B1 and B2, then both selections will show in the email.

 

I am using the code below but both options show on the email regardless of which box is checked in the form. Any advice is appreciated. 

 

#set($lead.exosomeBrochureDownloads = "B1,B2")
#if( !$lead.exosomeBrochureDownloadsS.isEmpty()&&$lead.exosomeBrochureDownloads.contains("B1") ) <a href="https://www.bio-techne.com/">Get B1 Brochure<br></a>
#end  
#if(!$lead.exosomeBrochureDownloadsS.isEmpty()&&$lead.exosomeBrochureDownloads.contains("B2") ) <a href="https://www.bio-techne.com/">Get B2 Brochure</a>
#end
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Email Script Token for Checkboxes

The very first thing your code does is hard-codes the property exosomeBrochureDownloads on the $lead object. This is fine for testing but means the person’s real value will never be used.

 

Then you proceed to check if the property $lead.exosomeBrochureDownloadsS is not empty (note the extra capital S at the end, you have not indicated what this property is) and run String.contains against $lead.exosomeBrochureDownloads.

 

The output should not be surprising since you have deliberately set the $lead.exosomeBrochureDownloads value to include 2 sub-values.

 

However, there are other major errors in your approach that are not fixed by removing the first line.

 

1. Marketo uses a semicolon-delimited structure for multivalued String fields, not comma-delimited.

 

2. You shouldn’t use String.contains against this field, you should split it into its actual sub-values. Otherwise you run the risk of an ambiguous sub-value (“A11” contains both “A1” and “A11”).

 

Thus more like:

## test only, remove in production
#set($lead.exosomeBrochureDownloads = "B1;B2")
## multivalued string to values
#set( $exosomeBrochureDownloadList = $lead.exosomeBrochureDownloads.split("\s*;\s*") )
#if( !$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadList.contains("B1") )
<a href="https://www.bio-techne.com/">Get B1 Brochure<br></a>##
#end
#if(!$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadList.contains("B2") )
<a href="https://www.bio-techne.com/">Get B2 Brochure</a>##
#end

Note I’m assuming $lead.exosomeBrochureDownloadsS with the extra S has some meaning.

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Email Script Token for Checkboxes

The very first thing your code does is hard-codes the property exosomeBrochureDownloads on the $lead object. This is fine for testing but means the person’s real value will never be used.

 

Then you proceed to check if the property $lead.exosomeBrochureDownloadsS is not empty (note the extra capital S at the end, you have not indicated what this property is) and run String.contains against $lead.exosomeBrochureDownloads.

 

The output should not be surprising since you have deliberately set the $lead.exosomeBrochureDownloads value to include 2 sub-values.

 

However, there are other major errors in your approach that are not fixed by removing the first line.

 

1. Marketo uses a semicolon-delimited structure for multivalued String fields, not comma-delimited.

 

2. You shouldn’t use String.contains against this field, you should split it into its actual sub-values. Otherwise you run the risk of an ambiguous sub-value (“A11” contains both “A1” and “A11”).

 

Thus more like:

## test only, remove in production
#set($lead.exosomeBrochureDownloads = "B1;B2")
## multivalued string to values
#set( $exosomeBrochureDownloadList = $lead.exosomeBrochureDownloads.split("\s*;\s*") )
#if( !$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadList.contains("B1") )
<a href="https://www.bio-techne.com/">Get B1 Brochure<br></a>##
#end
#if(!$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadList.contains("B2") )
<a href="https://www.bio-techne.com/">Get B2 Brochure</a>##
#end

Note I’m assuming $lead.exosomeBrochureDownloadsS with the extra S has some meaning.

 

norahpost
Level 1

Re: Velocity Email Script Token for Checkboxes

Thank you, this was helpful! I ended up using this code that worked. 

#set( $exosomeBrochureDownloadsSList = $lead.exosomeBrochureDownloadsS.split("\s*;\s*") )
#if( !$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadsSList.contains("B1") )
<a href="https://www.bio-techne.com/">Get B1 Brochure<br></a>
#end
#if(!$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadsSList.contains("B2") )
<a href="https://www.bio-techne.com/">Get B2 Brochure<br></a>
#end
#if(!$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadsSList.contains("B3") )
<a href="https://www.bio-techne.com/">Get B3 Brochure<br></a>
#end
#if(!$lead.exosomeBrochureDownloadsS.isEmpty() && $exosomeBrochureDownloadsSList.contains("B4") )
<a href="https://www.bio-techne.com/">Get B4 Brochure<br></a>
#end

To clarify, 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Email Script Token for Checkboxes

You shouldn't do the same comparison over and over. That's a bad habit that'll make your code harder to read. (And takes more resources to execute - not that you'd notice one-by-one but you want to follow the DRY principle.)

 

#set( $exosomeBrochureDownloadsSList = $lead.exosomeBrochureDownloadsS.split("\s*;\s*") )
#if( !$lead.exosomeBrochureDownloadsS.isEmpty() )
#if( $exosomeBrochureDownloadsSList.contains("B1") )
<a href="https://www.bio-techne.com/">Get B1 Brochure<br></a>
#end
#if( $exosomeBrochureDownloadsSList.contains("B2") )
<a href="https://www.bio-techne.com/">Get B2 Brochure<br></a>
#end
#if( $exosomeBrochureDownloadsSList.contains("B3") )
<a href="https://www.bio-techne.com/">Get B3 Brochure<br></a>
#end
#if( $exosomeBrochureDownloadsSList.contains("B4") )
<a href="https://www.bio-techne.com/">Get B4 Brochure<br></a>
#end
#end