SOLVED

Re: Email script - ${lead.Interest} contains "A"

Go to solution
Charles_THIERY
Level 3

Re: Email script - ${lead.Interest} contains "A"

Hi Sandford,

What is the way to make the negative test of what I have previously asked and with ";" instead of "," please? I thought by Adding "!" at the beginning would work... but it seems to not working:

  1. #set( $item = "Performance" )
  2. #set( $item2 = "Talent" )
  3. #if( !$lead.Interest__c.matches("(?i)(.*)(^|;)\s*${item}\s*(;|$)(.*)") ) 
  4. #elseif( !$lead.Interest__c.matches("(?i)(.*)(^|;)\s*${item2}\s*(;|$)(.*)") ) 
  5. #else

Sorry, you become a kind of my guru!

BR,

Charles

SanfordWhiteman
Level 10 - Community Moderator

Re: Email script - ${lead.Interest} contains "A"

When you reach the point of two lookups as opposed to a one-off, you don't want to repeat the same code. This is known the as the DRY principle in programming. As you will see below, the moment you add a second check, you want to refactor the whole approach because otherwise you will eventually screw up due to mistyping, and people will have trouble reading your code.

(There's nothing about two mostly-identical strings that says, "These are always supposed to differ only by this one character": they might as well differ by 100 characters. Totally identical strings in different lines of code also can't inform the reader -- which doesn't have to be someone else, it could be you a year from now  -- "Whatever string you put in Line 2 must be repeated in Line 4.")

Another incredibly useful way to frame your thinking is the Zero-One-Infinity principle.  For our purposes here, ZOI means that once you decide you want two lookups, you have to assume there will be a much higher number of lookups (maybe not "infinity" as the principle suggests, but the idea is "more than 1 = much more than 1"). ZOI means you should treat 2 as if it were 20, 200, or 2000. Imagine how crazy your script token would get if you copy-and-pasted-and-slightly-altered your code just 20 times.  Obey the DRY principle accordingly.

## generic list-like string scanner w/selectable delimiter

#macro( listContains $haystack $needle $delim )

#if( $haystack.matches("(?i)(.*)(${delim}|^)\s*${needle}\s*(${delim}|$)(.*)") )

true##

#else

false##

#end

#end

## convenience call w/semicolon

#macro( semiListContains $haystack $needle )

#listContains( $haystack $needle ';' )

#end

## convenience call w/comma

#macro( commaListContains $haystack $needle )

#listContains( $haystack $needle ',' )

#end

#if( "#semiListContains( $lead.Interest__c 'Talent' )" == "true" )

Does contain Talent.

#end

#if( !("#semiListContains( $lead.Interest__c 'Performance' )" == "true") )

Doesn't contain Performance.

#end

Charles_THIERY
Level 3

Re: Email script - ${lead.Interest} contains "A"

Hello Sanford,

Thank for this answer. I really need to dig into your proposal as it turns I have to create more complex dynamic email structure.

BR,

Charles

Charles_THIERY
Level 3

Re: Email script - ${lead.Interest} contains "A"

Hello Sanford,

I got your point and therefore I want to reduce my code as the minimum length possible and try to concentrate the editable section of my code on the top of my script.

I've seen your post on http://blog.teknkl.com/marketo-doesnt-like-velocimacros-for-output-but-define-is-fine/  but not sure if it's working out of a macro.

Anyway, I wanted to know if there is an expression in order to do this:

#set( $TP = "TP_A", "TP_B")

#set( $TP_A = "Button A", "https://www.wonderfulworld.com")

#set( $TP_B = "Button B", "https://www.hellworld.com")

#foreach( $asset in $TP )

     #if($lead.notengagedAssets.matches("(?i)(.*)(^|;)\s*${asset}\s*(;|$)(.*)") )

          <a href="${${asset}[1]}">${${asset}[0]}</a>

          ##I want to get the label out of the ${asset} variable and add the [...] to indicate which parameters to retreive.

     #end

#end

##The result expected should be:

          <a href="https://www.wonderfulworld.com">Button A</a>

          <a href="https://www.hellworld.com">Button B</a>

Is it possible? would it mess with the email click tracking of Marketo?

BR,

Charles

SanfordWhiteman
Level 10 - Community Moderator

Re: Email script - ${lead.Interest} contains "A"

Please open a new thread in Products (this shouldn't be in Champions, which is for Qs about the Champs program).