AnsweredAssumed Answered

Velocity macros being saved.. globally.. or some dark magic like that

Question asked by Stephen Baker on Nov 30, 2018
Latest reply on Dec 5, 2018 by Mark Price

I couldn't figure out why my macro was not updating on successive calls when trying to update the code. I did find out what was going on... but why it was... ¯\_(ツ)_/¯

 

Welp, turns out whenever the script token was saved a version of the macro at that time was "created in memory" - or some such thing like that - using the macro name, and any changes to the macro contents were not actually applying to future calls of the macro. I tried the unplug-it-and-plug-it-in-again method on previews, browser windows, etc., to no avail.

 

Is this how macros are supposed to function? Is there fine print for macros in Marketo?

 

Here is an example of two tests I made after updating a macro with new code:

 

Code 1:

#macro( getCreditUnionNumber3 $list $source )
#foreach ( $creditUnion in $list )
#if ( $creditUnion == $source )
#set ( $phoneNumber = $creditUnion[$source]) )
#break($getCreditUnionNumber)
#end
#set ( $a = $creditUnion )
#set ( $b = $creditUnion[$source] )
union = ${a}<br/>
number = ${b}<br/>
#end
#end

Called by: #getCreditUnionNumber3( $phoneList $leadSource )

Output 1:

number = ${creditUnion[$velocityCount].value}
test union = ${creditUnion[$velocityCount].key}
number = ${creditUnion[$velocityCount].value}
test union = ${creditUnion[$velocityCount].key}
number = ${creditUnion[$velocityCount].value}
test union = ${creditUnion[$velocityCount].key}
(...)

 

Code 2:

#macro( getCreditUnionNumber $list $source )
#foreach ( $creditUnion in $list )
#if ( $creditUnion == $source )
#set ( $phoneNumber = $creditUnion[$source]) )
#break($getCreditUnionNumber)
#end
#set ( $a = $creditUnion )
#set ( $b = $creditUnion[$source] )
union = ${a}<br/>
number = ${b}<br/>
#end
#end

Called by: #getCreditUnionNumber( $phoneList $leadSource )

Output 2:

number = ${b}
test union = [phone number was here]
number = ${b}
test union = [phone number was here]
number = ${b}
test union = [phone number was here]
(...)

 

It might be hard to follow along with all the noise above.

 

But if you track carefully, you'll see that the macro names changed for the two outputs, but the code contents did not change. However, if you are still following along , the rendered output of the loop for Code 1 is using a previous iteration of the macro "#getCreditUnionNumber3" where I was messing around with key-value pairs. (I had to increment the name to get past the issue and am using v3 for the example.) You should see that the current macros in Code 1 and Code 2 do not reference keys or values anywhere.

 

Btw, the code I was using was busted which was why literal VTL was being printed. That was resolved, don't think it's related.

 

The solution I found was renaming the macro every time I made a change to the macro contents.

Outcomes