SOLVED

Re: Valocity scripting token not working.

Go to solution
DeAnna_Humphrey
Level 2

Valocity scripting token not working.

Why is my script working in one of my workspaces and not the other?

## First, covert the variable to currency format

#set($total = $number.currency($${lead.Finance_Savings__c})) ##our code from before, e.g., $121,237.10

#set($stringLength = $total.length() - 3) ##get the total string length and calculate what we want to keep, e.g., 8 --note the specific spacing between the commands here! screwing up the syntax will crash it (e.g. if you remove the space)

#set($totalb = $total.substring(0,$stringLength)) ##takes the sub string of just the first 3 characters, e.g., $121,237

## Then, for the email output

${totalb}

@

pastedImage_1.pngpastedImage_0.png

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Valocity scripting token not working.

Do you have Finance_Savings__c checked off in the right-hand-side tree in Script Editor?

Also, use

$math.sub( $total.length(), 3 )

instead of the more fragile minus sign operator.

Also, what are you trying to do with the substring()?  You just want the number without decimal points?

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Valocity scripting token not working.

Do you have Finance_Savings__c checked off in the right-hand-side tree in Script Editor?

Also, use

$math.sub( $total.length(), 3 )

instead of the more fragile minus sign operator.

Also, what are you trying to do with the substring()?  You just want the number without decimal points?

DeAnna_Humphrey
Level 2

Re: Valocity scripting token not working.

pastedImage_0.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Valocity scripting token not working.

I don't really understand your response -- this is solved now, though?

Anyway, if you want the variable to be comma-thousands-delimited but not have a decimal point, you don't want number.currency().  By definition, Currency has two digits after the decimal point, which you just end up stripping off.  You just need the one line:

${esc.d}${number.format(lead.Finance_Savings__c)}

number.format() adds the commas (in the US locale, which I can see you're in) but not the decimal points.

DeAnna_Humphrey
Level 2

Re: Valocity scripting token not working.

Sanford,

Thank you for your assistance.  What my snippet revealed was I needed to checkmark the field at the program/folder level in all my workspaces.  I didn't realize when the scripting token is created it only applies to that program/folder and I would have to remark the finance savings token.  As far as the script, what I have is working.  Not sure what happened when I tried replacing out with your code suggestions, the code broke.  Thanks again for all your help.

Best regards,

DeAnna

SanfordWhiteman
Level 10 - Community Moderator

Re: Valocity scripting token not working.

Yes, a Velocity token is 2 things: code and context. If you use the same code without exporting necessary objects/fields into its context it won't work. (Or, more accurately, it's *unlikely* to work: it would still function if *another* token in the same email had exported the object.)