SOLVED

Re: Validation error using a macro in global velocity includes

Go to solution
Franky_Ruyssch2
Level 4

Validation error using a macro in global velocity includes

This is a implementation case which has been described in Sanfords blog post at:
https://blog.teknkl.com/velocity-poison-pill-throw-error-revisited/


I want to block sending an email if my velocity script has no output.

The idea is the use a global macro which has been defined in a Global Velocity token  ( {{my.velocity includes}} )

#macro( throw_v2 $message )
	#if( !$message.isEmpty() )
		#evaluate( "${esc.h}set( ${message} )" )
	#end
#end

In my email I include this token like {{my.velocity includes}}

Further in my email I include the next simple code ( as example )

#set( $output = '' )
#set( $nrOfLinksInOutput = 0 )
## render generated content

#if( $nrOfLinksInOutput == 0)
	 #throw_v2("ineligible")
#else
	#set( $output = 'Links available' )
#end
${output}

In preview mode this code is executed properly, but when I try to approve my mail I receive the next error :

Validation Error approving OPER-3649-UPSELL-2022.TESTMAIL3 —  <div>An error occurred when procesing the email Body! </div> <p>Encountered "ineligible" near</p> <div><pre >&lt;p&gt;#macro( throw_v2 $message )</pre><pre > #if( !$message.isEmpty() )</pre><pre class="x-form-item-label"> #evaluate( &quot;${esc.h}set( ${message} )&quot; )</pre><pre > #end</pre><pre >#end&lt;/p&gt; #set( $output = '' )</pre></div>

 

Can someone help me here? What am I doing wrong?

 

Franky Ruysschaert
1 ACCEPTED SOLUTION

Accepted Solutions
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Validation error using a macro in global velocity includes

I hope you included the code to print the output  in a separate velocity token and included it in the email, right? I tried this in my SB and it worked fine for me - I created two script tokens one having the macro and another having the business logic to render the generated content and calling the macro if required to stop the send.

 

Script Token - 1

 

#macro( throw_v2 $message )
#if( !$message.isEmpty() )
#evaluate( "${esc.h}set( ${message} )" )
#end
#end

 

Script Token - 2

 

##static value set in the $nrOfLinksInOutput variable for the purpose of testing
#set($nrOfLinksInOutput = 0)
#if($nrOfLinksInOutput.equals(0))
#throw_v2("ineligible")
#else
#set($output = 'Links available')
#end
${output}

 

I included both the script tokes in an email, and tried sending it to a test lead and the email encountered soft bounce as expected, then I changed the value of the $nrOfLinksInOutput to a non-zero value in the script token, and as expected in that case the email went out fine, i.e. did not encounter any soft bounce.

View solution in original post

3 REPLIES 3
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Validation error using a macro in global velocity includes

I hope you included the code to print the output  in a separate velocity token and included it in the email, right? I tried this in my SB and it worked fine for me - I created two script tokens one having the macro and another having the business logic to render the generated content and calling the macro if required to stop the send.

 

Script Token - 1

 

#macro( throw_v2 $message )
#if( !$message.isEmpty() )
#evaluate( "${esc.h}set( ${message} )" )
#end
#end

 

Script Token - 2

 

##static value set in the $nrOfLinksInOutput variable for the purpose of testing
#set($nrOfLinksInOutput = 0)
#if($nrOfLinksInOutput.equals(0))
#throw_v2("ineligible")
#else
#set($output = 'Links available')
#end
${output}

 

I included both the script tokes in an email, and tried sending it to a test lead and the email encountered soft bounce as expected, then I changed the value of the $nrOfLinksInOutput to a non-zero value in the script token, and as expected in that case the email went out fine, i.e. did not encounter any soft bounce.

Franky_Ruyssch2
Level 4

Re: Validation error using a macro in global velocity includes

Hi Darshil,

 

First of all, thank you for taking the time to look at my case, i really appreciate it.

I have put your above suggested code into 2 new tokens and the email is working.
I can't pinpoint the differences exactly, but at least I can build on this working part.

Franky Ruysschaert
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Validation error using a macro in global velocity includes

Cool, glad that it's working now. 🙂