Can not approve email due to velocity script (problem?) | Community
Skip to main content
Franky_Ruyssch2
New Participant
April 4, 2022
Solved

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

  • April 4, 2022
  • 3 replies
  • 4342 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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

 

 

 

 

 

3 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
April 5, 2022

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
New Participant
April 5, 2022

not applicable

Franky Ruysschaert
Jo_Pitts1
Community Manager
April 4, 2022

@franky_ruyssch2 

Maybe try this?

#if( !$usedURLArray.size().isEmpty() ) ## Do your stuff here #end
Darshil_Shah1
Community Manager
April 4, 2022

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
New Participant
April 4, 2022

Hi, this is my error :

 

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
New Participant
April 4, 2022

 

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