SOLVED

Re: Email Script Token Troubles

Go to solution
Zach_Bollinger
Level 2

Email Script Token Troubles

Hello all,

 

I am trying to get 3 (A,B,C) different phone numbers to appear in an email based on an email script token and have hit a wall trying to find the issue in my code. When I try to preview a specific person, I get defaulted to the 3rd phone number. The referring fields (A and B)  are text fields and Standard Objects in our Database.

 

##check if the lead is an A
#if(${lead.XX_A_relationshipmanagertext} =="name 1"#OR"name 2")
            ##if the lead has name or name, use the phone number A 'XXX-XXX-XXXX'
    #set(${lead.XX_A_relationshipmanagertext} = "XXX-XXX-XXXX ")
##check if the lead is an B
#elseif(${lead.XX_B_relationshipmanagertext} ==" name 3 "#OR" name 2  "#OR " name 4 "#OR" name 5")
            ##if the lead has name, or name, or name, or name, use the phone number B 'XXX-XXX-XXXX'
    #set(${lead.XX_B_relationshipmanagertext} = "'XXX-XXX-XXXX ")
#else
            ##otherwise use phone number C  'XXX-XXX-XXXX' 
    #set(${lead.XX_B_relationshipmanagertext} #OR ${lead.XX_A_relationshipmanagertext} == "XXX.XXX.XXXX")
#end
##print the phone number
(${lead.XX_B_relationshipmanagertext} #OR ${lead.XX_A_relationshipmanagertext})
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token Troubles

That code won’t even compile, so it’s a bit beyond a question of logic.

 

The preferred operator for Boolean OR in Velocity is double-pipe ||. Not recommended but also supported is literal OR. The hash-OR (#OR) you seem to be trying is not supported.

 

Also a bunch of other attempted assignments that simply won’t work.

 

You’re better off not using any OR statements but rather a collection-centric approach. Create lists of options and check if the List.contains() the current value.

#set( $relationshipManagerLookup = [
{
 "fieldName" : "XX_A_relationshipmanagertext",
 "text" : ["name 1", "name 2"],
 "phone" : "212-123-4567"
},
{
 "fieldName" : "XX_B_relationshipmanagertext",
 "text" : ["name 3", "name 4", "name 5"],
 "phone" : "313-234-5678"
}
] )
#set( $defaultRelationshipManager = {
 "phone" : "414-345-6789"
} )
##
#foreach( $matchable in $relationshipManagerLookup )
#if( $matchable.text.contains($lead[$matchable.fieldName]) )
#set( $matchedRelMgr = $matchable )
#break
#end
#end
#set( $matchedRelMgr = $display.alt($matchedRelMgr,$defaultRelationshipManager) )
Phone: ${matchedRelMgr.phone}

 

P.S. I recommend you read my past Velocity posts & comments if you’re going to be supporting VTL tokens in production.... you don’t want to be in an urgent troubleshooting situation without wider experience of the Velocity ecosystem.

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token Troubles

That code won’t even compile, so it’s a bit beyond a question of logic.

 

The preferred operator for Boolean OR in Velocity is double-pipe ||. Not recommended but also supported is literal OR. The hash-OR (#OR) you seem to be trying is not supported.

 

Also a bunch of other attempted assignments that simply won’t work.

 

You’re better off not using any OR statements but rather a collection-centric approach. Create lists of options and check if the List.contains() the current value.

#set( $relationshipManagerLookup = [
{
 "fieldName" : "XX_A_relationshipmanagertext",
 "text" : ["name 1", "name 2"],
 "phone" : "212-123-4567"
},
{
 "fieldName" : "XX_B_relationshipmanagertext",
 "text" : ["name 3", "name 4", "name 5"],
 "phone" : "313-234-5678"
}
] )
#set( $defaultRelationshipManager = {
 "phone" : "414-345-6789"
} )
##
#foreach( $matchable in $relationshipManagerLookup )
#if( $matchable.text.contains($lead[$matchable.fieldName]) )
#set( $matchedRelMgr = $matchable )
#break
#end
#end
#set( $matchedRelMgr = $display.alt($matchedRelMgr,$defaultRelationshipManager) )
Phone: ${matchedRelMgr.phone}

 

P.S. I recommend you read my past Velocity posts & comments if you’re going to be supporting VTL tokens in production.... you don’t want to be in an urgent troubleshooting situation without wider experience of the Velocity ecosystem.

Zach_Bollinger
Level 2

Re: Email Script Token Troubles

Thank you for all of the help, I am reading up on velocity currently. Your code works well!