Skip to main content
Level 2
Sep 12, 2025 12:52 PM UTC
Solved

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

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?

SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Sep 12, 2025 5:07 PM UTC
#set( $stripTrailingDot = $YourField.replaceAll("\.$","") )

5 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Sep 12, 2025 5:07 PM UTC
#set( $stripTrailingDot = $YourField.replaceAll("\.$","") )
Translate
hcolemanAuthor
Level 2
Sep 12, 2025 6:22 PM UTC

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.

 

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?

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Sep 12, 2025 6:39 PM UTC

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

Translate