SOLVED

Re: Edit Script Token wrong result

Go to solution
LydiaKarakuz
Level 2

Edit Script Token wrong result

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

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Edit Script Token wrong result

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.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Edit Script Token wrong result

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

 

syntax_vtl.png

LydiaKarakuz
Level 2

Re: Edit Script Token wrong result

 

#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
Level 10 - Community Moderator

Re: Edit Script Token wrong result

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.

LydiaKarakuz
Level 2

Re: Edit Script Token wrong result

Thank you sooo much! It worked great!