SOLVED

Velocity script to identify if the last character of the string is a period and remove it

Go to solution
hcoleman
Level 2

I have an existing lead field that contains the value for user Company Names, and with some company name ending in "Inc." we get an extra period at the end of the sentence where the token is placed.

I want to set up a script token that can identify if the last character in the lead field string is a period and remove it. I've looked into substring a bit, but haven't found a working solution. 

 

Does anyone have any suggestions?

2 ACCEPTED SOLUTIONS
SanfordWhiteman
Level 10 - Community Moderator
#set( $stripTrailingDot = $YourField.replaceAll("\.$","") )

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator
5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator
#set( $stripTrailingDot = $YourField.replaceAll("\.$","") )
hcoleman
Level 2

Thank you for getting back to me. When I placed the code into the token, it returns the varibale as text. In the image below, I was testing our original token next to my new token to see how it renders, and as you can see I'm getting "$stripTrailingDot" as text.

Screenshot 2025-09-12 at 2.13.47 PM.png

I'm fairly new at using velocity script and don't know exactly how to properly display the value of the lead. The code is defined below.

#set( $stripTrailingDot = $lead.Company.replaceAll("\.$","") )
${stripTrailingDot}

 

Should I be referencing something other than $stripTrailingDot to get my lead.Company value to display?

SanfordWhiteman
Level 10 - Community Moderator

Do you have that field checked in the tree on the right-hand-side of Script Editor?

hcoleman
Level 2

No, I do not, should I have that field checked?

SanfordWhiteman
Level 10 - Community Moderator

Of course.