SOLVED

Velocity Scripting to change displayed token value

Go to solution
Eric1001
Level 1

Velocity Scripting to change displayed token value

Ok I am doing nothing very complicated. I am looking at a field which is a picklist of values (specifically currency type). Based on that I need to display a very specific value. I started to write a velocity scrip and tested it and got it to partially work, but when I changed the value to be the price it stopped working. If I could get advice on how to fix this I appreciate it. I put the never version of the script below and appreciate any advise on what I am doing wrong.

 

##contact currency preference and print specific currency value
#if(${lead.CurrencyIsoCode}=="USD")
    #$180
#elseif(${lead.CurrencyIsoCode}=="EUR")
    #€144
#elseif(${lead.CurrencyIsoCode}=="AUS")
    #$277.20
#elseif(${lead.CurrencyIsoCode}=="JPY")
    #¥18,000
#elseif(${lead.CurrencyIsoCode}=="CAD")
    #$252
#elseif(${lead.CurrencyIsoCode}=="GBP")
    #£144
#else(${lead.CurrencyIsoCode}==$NULL)
    #{lead.CurrencyIsoCode}
#end

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting to change displayed token value

  • Don’t use ${formal} references inside directives, use $simple
  • Don’t use the == operator, use .equals (== causes hard-to-debug errors)
  • Don’t use literal $ to print a dollar sign, use ${esc.d}
  • Your last #else doesn’t make sense, #else doesn’t have conditions

 

##contact currency preference and print specific currency value
#if( $lead.CurrencyIsoCode.equals("USD") )
    ${esc.d}180
#elseif( $lead.CurrencyIsoCode.equals("EUR") )
    €144
#elseif( $lead.CurrencyIsoCode.equals("AUS") )
    ${esc.d}277.20
#elseif( $lead.CurrencyIsoCode.equals("JPY") )
    ¥18,000
#elseif( $lead.CurrencyIsoCode.equals("CAD") )
    ${esc.d}252
#elseif( $lead.CurrencyIsoCode.equals("GBP") )
    £144
#else
    ${lead.CurrencyIsoCode}
#end

 

 

 

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting to change displayed token value

  • Don’t use ${formal} references inside directives, use $simple
  • Don’t use the == operator, use .equals (== causes hard-to-debug errors)
  • Don’t use literal $ to print a dollar sign, use ${esc.d}
  • Your last #else doesn’t make sense, #else doesn’t have conditions

 

##contact currency preference and print specific currency value
#if( $lead.CurrencyIsoCode.equals("USD") )
    ${esc.d}180
#elseif( $lead.CurrencyIsoCode.equals("EUR") )
    €144
#elseif( $lead.CurrencyIsoCode.equals("AUS") )
    ${esc.d}277.20
#elseif( $lead.CurrencyIsoCode.equals("JPY") )
    ¥18,000
#elseif( $lead.CurrencyIsoCode.equals("CAD") )
    ${esc.d}252
#elseif( $lead.CurrencyIsoCode.equals("GBP") )
    £144
#else
    ${lead.CurrencyIsoCode}
#end

 

 

 

Eric1001
Level 1

Re: Velocity Scripting to change displayed token value

Thank you so much for helping me review this and correct the mistakes. 

Eric1001
Level 1

Re: Velocity Scripting to change displayed token value

@SanfordWhiteman quick question I have been using this script for a while sometimes it refuses to fire. I make a minor adjustment like adding a set of NULL quotes then deleting them and it then fires correctly, but now I can't get it to run. Do you have any advise on how to make this scripting run more consistently?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting to change displayed token value

What do you mean by “refuses to fire” exactly? On rare occasions a token gets corrupted under the hood and needs to be recreated from scratch, but I’ve never seen this happen with the same piece of code multiple times across different rebuilt tokens.

Eric1001
Level 1

Re: Velocity Scripting to change displayed token value

By refuses to fire I mean the token displays nothing at all and it seems to not be working. In this case after further inspection my college made a mistake and uploaded some of the data under the wrong variable.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting to change displayed token value

Makes sense, so it is running but the field isn't filled in so even the fallback case prints an empty line.