Edit Script Token wrong result | Community
Skip to main content
New Participant
May 8, 2020
Solved

Edit Script Token wrong result

  • May 8, 2020
  • 1 reply
  • 2670 views

Hello all, I fell like I am getting crazy. I want to create a solution in wich if there is a phone number of a credit advisor than display it, if it is empty display the default number. The default number is displayed without any problem. But instead of the credit Advisor Phone number it displays "bestOfferBankAmountOfRate". 

 

I tested if the {{lead.creaditadvisorphne}} works and it does. So I have no clue where I made a mistake. This is the script I used:

 

#set( $a = ${lead.creditAdvisorPhone})
#if("$a" == "")
#set($b = "0800 XXX XX XX")
#end
${b}

 

Thank you in advance

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

You must use descriptive variable names: $a and $b are no way to code! You will encounter errors that are impossible to debug if you do this in Velocity, since there is only one global variable scope.

 

It sounds like you want this:

 

#set( $defaultAdvisorPhone = "0800 000 98 00" ) #if( !$lead.creditAdvisorPhone.isEmpty() ) #set( $creditAdvisorPhone = $lead.creditAdvisorPhone ) #else #set( $creditAdvisorPhone = $defaultAdvisorPhone ) #end ${creditAdvisorPhone}

 

 

Not sure what you were expecting to happen before, but I suspect you reused $b by accident.

 

Also note the proper use (or non-use) of curly braces and quotes in the code.

1 reply

SanfordWhiteman
New Participant
May 8, 2020

Can you highlight your code using the syntax highlighter, please? Then we'll continue. 

 

New Participant
May 9, 2020

 

#set( $a = ${lead.creditAdvisorPhone}) #if("$a" == "") #set($b = "0800 000 XX XX") #end ${b}

 

 

Hello @sanfordwhiteman 

 

thank you in advance, as wished I highlighted the code.

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
May 9, 2020

You must use descriptive variable names: $a and $b are no way to code! You will encounter errors that are impossible to debug if you do this in Velocity, since there is only one global variable scope.

 

It sounds like you want this:

 

#set( $defaultAdvisorPhone = "0800 000 98 00" ) #if( !$lead.creditAdvisorPhone.isEmpty() ) #set( $creditAdvisorPhone = $lead.creditAdvisorPhone ) #else #set( $creditAdvisorPhone = $defaultAdvisorPhone ) #end ${creditAdvisorPhone}

 

 

Not sure what you were expecting to happen before, but I suspect you reused $b by accident.

 

Also note the proper use (or non-use) of curly braces and quotes in the code.