SOLVED

Email Script - contains one of multiple values

Go to solution
Travis_Wittenbu
Level 2

Email Script - contains one of multiple values

Check out this script. It currently looks in our 'lead.Subscribed_Products_From_Account__c' field for various words and if it finds a match, outputs a link, if it doesn't find a match outputs a different link.

 

#if( $lead.Subscribed_Products_From_Account__c.contains("Alpha"))
<b><a href="https://mysite.com">https://mysite.com</a></b>*
#elseif( $lead.Subscribed_Products_From_Account__c.contains("Beta"))
<b><a href="https://mysite.com">https://mysite.com</a></b>*
#elseif( $lead.Subscribed_Products_From_Account__c.contains("Gamma"))
<b><a href="https://mysite.com">https://mysite.com</a></b>*
#else
<b><a href="https://NOTmysite.com">https://NOTmysite.com</a></b>*
#end

 

 

How can I combine the first 3 rules into a single rule?  I have tried the option below but it does not work - 

 

#if( $lead.Subscribed_Products_From_Account__c.contains("Alpha","Beta","Gamma"))
<b><a href="https://mysite.com">https://mysite.com</a></b>*
#else
<b><a href="https://NOTmysite.com">https://NOTmysite.com</a></b>*
#end

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script - contains one of multiple values

String.contains() only takes a single argument, a single string. Any other arguments cause the code to throw an error, which Velocity treats as a null result.

 

To check for multiple substrings in a string, use a regular expression and String.matches().

#if( $lead.Subscribed_Products_From_Account__c.matches(".*(Alpha|Beta|Gamma).*") )

 

Is this value you're searching actually a delimited string, though? Because you shouldn't just be scanning left-to-right it if so. You should split it on the delimiter (creating an array) then see if the array contains any of your interesting values.

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script - contains one of multiple values

String.contains() only takes a single argument, a single string. Any other arguments cause the code to throw an error, which Velocity treats as a null result.

 

To check for multiple substrings in a string, use a regular expression and String.matches().

#if( $lead.Subscribed_Products_From_Account__c.matches(".*(Alpha|Beta|Gamma).*") )

 

Is this value you're searching actually a delimited string, though? Because you shouldn't just be scanning left-to-right it if so. You should split it on the delimiter (creating an array) then see if the array contains any of your interesting values.

View solution in original post