SOLVED

Can not approve email due to velocity script (problem?)

Go to solution
Franky_Ruyssch2
Level 4

Can not approve email due to velocity script (problem?)

Take the following code

#set($nrOfLinksInOutput = 1)
#if($nrOfLinksInOutput.equals(0))
   #throw_v3("ineligible")
#else
   #set($output = 'Links available')
#end

This above works, and the email can be approved in the cases where
$nrOfLinksInOutput = 1 & $nrOfLinksInOutput = 0 ( the throw case )

 

Of course this is a test case, the reality relies on the length of an array
So this is the ‘real’ code

 

#set($usedURLArray = [] )

Some processing that can add items to the array
and then:

#set($usedURLArrayLength = $usedURLArray.size() )
#if($usedURLArrayLength.equals(0))
	#throw_v3("ineligible")
#else
	##set($output = 'Links available')
#end

This code doesn’t succeed, and I am not able to approve my email.
Someone who can tell me what the problem could be?

Franky Ruysschaert
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Can not approve email due to velocity script (problem?)

Your description of it working when the comparison is to a hard-coded value instead of to the live Array.size() doesn’t make sense. And I can’t reproduce any difference between these cases.

 

In fact, you should expect the error on approval whenever the #throw_v3 is called — that’s what it’s supposed to do! You don’t have any additional condition that means “is the array empty and am I not in the process of approving right now?”

 

You can check for non-empty $mktmail.Email_Address:

#set($usedURLArrayLength = $usedURLArray.size() )
#if($mktmail.Email_Address.isEmpty() && $usedURLArrayLength.equals(0))
#throw_v3("ineligible")
#else
Links available
#end

 

 

 

 

 

View solution in original post

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

Re: Can not approve email due to velocity script (problem?)

I don't think there's an error in the if else construct - I tried the below script in my SB and I didn't have any issues in approving the email or getting the macro called for the empty array case resulting in to an expected soft bounce:

 

#set($usedURLArray = [])
#set($usedURLArrayLength = $usedURLArray.size())
#if($usedURLArrayLength.equals(0))
#throw_v3("ineligible")
#else
#set($output = 'Links available')
#end
${output}

 

Could you potentially be having an error in the part where you're adding the array elements? It would help if you can share the error that you're seeing while approving the email.

Franky_Ruyssch2
Level 4

Re: Can not approve email due to velocity script (problem?)

Hi, this is my error :
Schermafbeelding 2022-04-04 om 17.16.48.png

 

And my complete code : json data not included , but present in
#set( $dataNLD = '[xxxx]' )

The whole system is working in preview, but I am not able to approve my email

 

 

Franky Ruysschaert
Franky_Ruyssch2
Level 4

Re: Can not approve email due to velocity script (problem?)

 

json data not included but part of
#set( $dataNLD = '[{ xxx }]' )

## Other variables
#set($mybreak = '<br>' )
#set($output = '<span style="font-size:14px;margin-top:0;margin-bottom:0;">' )
#set($linkpart1NLD = "<a style='color:#00ADEF;text-decoration:underline;' href='https://www.dataline.eu/nl/" )
#set($linkpart1FRA = "<a style='color:#00ADEF;text-decoration:underline;' href='https://www.dataline.eu/fr/" )
#set($linkpart1ENG = "<a style='color:#00ADEF;text-decoration:underline;' href='https://www.dataline.eu/en/" )
#set($linkpart1DEU = "<a style='color:#00ADEF;text-decoration:underline;' href='https://www.dataline.eu/de/" )
#set($linkpart1SPA = "<a style='color:#00ADEF;text-decoration:underline;' href='https://www.dataline.eu/es/" )
#set($linkpart2 = "'>" )
#set($linkpart3 = "</a>" )
#set($openList = "<ul>" )
#set($closeList = "</ul>" )
#set($openListItem = "<li>" )
#set($closeListItem = "</li>" )
#set($moduleFound = "FALSE" )
#set($lisaCPCriteria = ${lead.lisa_cp_criteria} )
#set($lisaCPAttribuut = ${lead.lisa_cp_att} )
#set($lisaRelCriteria = ${lead.lisa_rel_criteria} )
#set($lisaCPLanguageLisa = ${lead.lisa_cp_language_lisa} )
#set($googleUTMString = "?utm_source=marketo&utm_medium=email&utm_campaign=3649" )
#set($usedURLArray = [] )
#set($closeDiv = "</span>")

## Check : https://blog.teknkl.com/marketo-json-fields-in-velocity/
## load correct json structure based on lead lisa_cp_language_lisa
#if( $lisaCPLanguageLisa == "NLD" )
  #set( $upsellData = '#set( $upsellData = ' + $dataNLD + ' )' )
#elseif( $lisaCPLanguageLisa == "FRA" )
  #set( $upsellData = '#set( $upsellData = ' + $dataFRA + ' )' )         
#elseif( $lisaCPLanguageLisa == "DEU" )
  #set( $upsellData = '#set( $upsellData = ' + $dataDEU + ' )' )        
#elseif( $lisaCPLanguageLisa == "SPA" )
  #set( $upsellData = '#set( $upsellData = ' + $dataSPA + ' )' )          
#else
  #set( $upsellData = '#set( $upsellData = ' + $dataENG + ' )' )
#end
#evaluate( $upsellData )

#if( ! $lisaRelCriteria.length().equals(0) )
	## get upsellmodule part from lisa_rel_criteria
  	#set ( $upsellModulesStrStartPos = $lisaRelCriteria.indexOf('"70":') )
  	#set ( $upsellModulesStrStartPos = ${upsellModulesStrStartPos} + 6 )
	#set ( $upsellModulesStrEndPos = $lisaRelCriteria.indexOf("]",${upsellModulesStrStartPos}) )
	#set ( $upsellModulesStr = $lisaRelCriteria.substring($upsellModulesStrStartPos ,$upsellModulesStrEndPos))
	##set ( $output = "${output} upsellmodules : ${upsellModulesStr} ${mybreak}")
	## create array of indexes from this string
	#set( $leadUpsellModulesArr = $upsellModulesStr.split(',') )
  	#set($modules = '')
    ## loop all upsell modules, and display ( only for testing )
    #foreach ($leadUpsellModule in $leadUpsellModulesArr)
        #set( $modules = "${modules} $leadUpsellModule.substring(1,5) ${mybreak}")
    #end
    ##set( $output = "${output} DEBUG INFO: ${mybreak} ")
    ##set ( $output = "${output} Lead upsell modules ${mybreak} ")
    ##set ( $output = "${output} ${modules} ${mybreak} ${mybreak} ")
	
    ## Check if the contact is CEO or Project responsible
	#if( $lisaCPCriteria.contains("3284") || $lisaCPCriteria.contains("3282") )
   		##set( $output = "${output} DEBUG INFO: ${mybreak} ")
   		##set( $output = "${output} Persoon is een CEO of responsible project. Include all data from all modules. ${mybreak} ${mybreak}")
   		#set( $output = "${output} ${openList}" ) 
        ## loop all upsell modules and display data in correct language
   		#foreach ($leadUpsellModule in $leadUpsellModulesArr)
        	#set( $moduleFound = "FALSE" )
            #foreach( $j in $upsellData )
          		#if( ${j.id} == $leadUpsellModule.substring(1,5))
                    ##set( $output = "${output} DEBUG INFO: ${mybreak} ")
                    ##set( $output = "${output} module gevonden in json :  $leadUpsellModule.substring(1,5) ${mybreak} ${mybreak} ")
                    #set( $moduleFound = "TRUE" )
                    ## check if the found url isn't already present in the output, via usedURLArray
                    #set( $res = $usedURLArray.contains( ${j.u} ))
                    ##set( $output = "${output} res = ${res} ${mybreak} ")	
                    #if( $res == 'false' )
                        ##set( $output = "${output} URL komt nog niet voor ${mybreak} ")	
                        #set( $extra = $usedURLArray.add(${j.u}) )
                        ##case 1
                        ##set( $output = "${output} ${openListItem} ${j.i} ${mybreak}${mybreak} ${linkpart1NLD}${j.u}${googleUTMString}${linkpart2}${j.t}${linkpart3} ${closeListItem} ${mybreak}")
                        ##case 2
                        #set( $output = "${output} ${openListItem} ${linkpart1NLD}${j.u}${googleUTMString}${linkpart2}${j.t}${linkpart3} ${closeListItem}")
                    #else
                        ##set( $output = "${output} URL komt reeds voor ${j.u} ${mybreak} ")	
                    #end
                    #break($foreach)
          		#end	
			#end

            ## detect if the module was not found.
            #if( ${moduleFound} == "FALSE" )
                ##set( $output = "${output} DEBUG INFO: ${mybreak} ")
                ##set( $output = "${output} module NIET gevonden in json :  $leadUpsellModule.substring(1,5) ${mybreak} ${mybreak} ")
            #end
        #end 
        #set( $output = "${output} ${closeList}${closeDiv}" )    
    #else
    	##set( $output = "${output} DEBUG INFO: ${mybreak} ")
  		##set( $output = "${output} No Responsible CEO / Project ${mybreak}")

        #if( ! $lisaCPAttribuut.length().equals(0) )
			#if( $lisaCPAttribuut.contains('"1184":') )
      			##1. get the person must used functions and store in array mostUsedFunctionsArr
                #set ( $personMostUsedFunctionsStrStartPos = $lisaCPAttribuut.indexOf('"1184":'))
                #set ( $personMostUsedFunctionsStrStartPos = ${personMostUsedFunctionsStrStartPos} + 9 )
                #set ( $personMostUsedFunctionsStrEndPos = $lisaCPAttribuut.indexOf("]",${personMostUsedFunctionsStrStartPos}) )
                #set ( $personMostUsedFunctionsStr = $lisaCPAttribuut.substring($personMostUsedFunctionsStrStartPos,$personMostUsedFunctionsStrEndPos))
                #set ( $personMostUsedFunctionsArr = $personMostUsedFunctionsStr.split(',') )
                ## TEST: display the most used function from the lead
                ##set ( $output = "${output} ${mybreak}")
                ##foreach ($mostUsedFunction in $personMostUsedFunctionsArr)
                    ##set( $output = "${output} DEBUG INFO: ${mybreak} ")
                    ##set ( $output = "${output} most used functions from lead : $mostUsedFunction ${mybreak}")
                ##end
                ##set ( $output = "${output} ${mybreak}")
                #set( $output = "${output} ${openList}" ) 

                ##2. Loop the defined upsell modules for this person, defined at company level
                #foreach ($leadUpsellModule in $leadUpsellModulesArr)
                    ##set ( $output = "${output} upsell module defined for this person ${leadUpsellModule} ${mybreak} ")
                    ##3. find the defined module in the module data array
                    #foreach( $j in $upsellData )
                        #if( ${j.id} == $leadUpsellModule.substring(1,5))
                            ##4. Get the related functions
                            ##set( $output = "${output} DEBUG INFO: ${mybreak} ")
                            ##set ( $output = "${output} Module gevonden : $leadUpsellModule.substring(1,5) ${mybreak}")
                            ##set ( $output = "${output} Module gevonden functions : ${j.f} ${mybreak} ${mybreak}")

                            ##5. Loop the functions array ( data ) , and check if the function id is present in the function id array from this person
                            #foreach ( $k in ${j.f} )
                                ##set ( $output = "${output} Uit definitions array: $k ${mybreak}")
                                #if($personMostUsedFunctionsArr.contains("${k}"))
                                    ## check if the found url isn't already present in the output, via usedURLArray
                                    #set( $res = $usedURLArray.contains( ${j.u} ))
                                    #if( $res == 'false' )
                                    ##set( $output = "${output} URL komt nog niet voor ${mybreak} ")	
                                        #set( $extra = $usedURLArray.add(${j.u}) )
                                        ##set( $output = "${output} ${j.i} ${mybreak} ${linkpart1NLD}${j.u}${googleUTMString}${linkpart2}${j.t}${linkpart3} ${mybreak}")
                                        ##case1
                                        ##set( $output = "${output} ${openListItem} ${j.i} ${mybreak}${mybreak} ${linkpart1NLD}${j.u}${googleUTMString}${linkpart2}${j.t}${linkpart3} ${closeListItem} ${mybreak}")
                                        ##case2
                                        #set( $output = "${output} ${openListItem} ${linkpart1NLD}${j.u}${googleUTMString}${linkpart2}${j.t}${linkpart3} ${closeListItem}")
                                    #end
                                    #break($foreach)
                                #end
                  			#end    	

              			#end 
          			#end
      			#end
      			#set( $output = "${output} ${closeList}${closeDiv}" ) 
    		#end
        #end
    #end
#end



##set($nrOfLinksInOutput = 1)
#set($usedURLArrayLength = $usedURLArray.size() )
##if($nrOfLinksInOutput.equals(0))
#if($usedURLArrayLength.equals(0))
	#throw_v3("ineligible")
#else
	##set($output = 'Links available')
    ${output}
#end

 

All works well in preview, but I am not able to approve my email

 

Franky Ruysschaert
SanfordWhiteman
Level 10 - Community Moderator

Re: Can not approve email due to velocity script (problem?)

That can’t be working code because it’s missing a final

#end

 

Franky_Ruyssch2
Level 4

Re: Can not approve email due to velocity script (problem?)

The complete mail is working ( no errors in the code ) as long as I do not use the array length at the end to decide if I have to throw the exception. Only when using that variable I have this problem.

Franky Ruysschaert
Jo_Pitts1
Level 10 - Community Advisor

Re: Can not approve email due to velocity script (problem?)

@Franky_Ruyssch2 

Maybe try this?

#if( !$usedURLArray.size().isEmpty() )
  ## Do your stuff here
#end
SanfordWhiteman
Level 10 - Community Moderator

Re: Can not approve email due to velocity script (problem?)

Your description of it working when the comparison is to a hard-coded value instead of to the live Array.size() doesn’t make sense. And I can’t reproduce any difference between these cases.

 

In fact, you should expect the error on approval whenever the #throw_v3 is called — that’s what it’s supposed to do! You don’t have any additional condition that means “is the array empty and am I not in the process of approving right now?”

 

You can check for non-empty $mktmail.Email_Address:

#set($usedURLArrayLength = $usedURLArray.size() )
#if($mktmail.Email_Address.isEmpty() && $usedURLArrayLength.equals(0))
#throw_v3("ineligible")
#else
Links available
#end

 

 

 

 

 

Franky_Ruyssch2
Level 4

Re: Can not approve email due to velocity script (problem?)

not applicable

Franky Ruysschaert
Franky_Ruyssch2
Level 4

Re: Can not approve email due to velocity script (problem?)

Hi Sanford

After further looking into your answer, I could solve the issue.

 

The error had nothing to do with syntax problems in the code. It was indeed the problem of getting the email approved, and therefore indeed I needed to alter the code temporarily.

After the approval I removed the special condition, and now it is working as expected.
For those for whom the script could not generate output, the error is called, and I find a soft bounce in their activity log.
Thanks for all the feedback!

Franky Ruysschaert