Skip to main content
Eoin_Lyons1
Level 2
Sep 4, 2019 11:44 PM UTC
Solved

Velocity script adding a space before my URL

Hi, 

I don't fully understand the code below, but am hoping someone who does can tell me why there's a space being inserted before my URL when I apply this script token to an email.

Thanks!

#set($Calendly = $display.alt($OpportunityList.get(0).Calendly_OC_Checkin__c.trim(),""))

#if(
$Calendly.isEmpty() ||
$Calendly.indexOf(" ") == 1
)
https://calendly.com/welcome-to-bench/account-check-in##
#else
#set($Calendly = $Calendly.trim())
$display.capitalize($Calendly.toLowerCase())##
#end‍‍‍‍‍‍‍‍‍‍‍
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Sep 5, 2019 5:15 PM UTC

You've got leading whitespace as well when you use the fallback value (check that indent on line 10). This code has no extraneous printable whitespace:

#set( $Calendly = $display.alt( $OpportunityList.get(0).Calendly_OC_Checkin__c.trim(),"" ) )
#if(
$Calendly.isEmpty() ||
$Calendly.indexOf(" ") == 1
)
https://calendly.com/welcome-to-bench/account-check-in##
#else
#set( $Calendly = $Calendly.trim() )
$display.capitalize( $Calendly.toLowerCase() )##
#end‍‍‍‍‍‍‍‍‍‍

Note how there are spaces inside the parens. That's totally fine (and necessary to stay sane when coding) because it's not printable.

11 replies

SanfordWhiteman
User Group Leader
User Group Leader
Sep 4, 2019 11:54 PM UTC

Line 2 is whitespace. Velocity doesn't insert whitespace, but it always *preserves* whitespace.

Translate
Eoin_Lyons1
Level 2
Sep 5, 2019 5:06 PM UTC

Hey Sanford - that's good to know. What's the best way to get rid of it? I deleted this line and even mashed it together so it read like

__c.trim(),""))#if(

... but neither worked

Translate
SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Sep 5, 2019 5:15 PM UTC

You've got leading whitespace as well when you use the fallback value (check that indent on line 10). This code has no extraneous printable whitespace:

#set( $Calendly = $display.alt( $OpportunityList.get(0).Calendly_OC_Checkin__c.trim(),"" ) )
#if(
$Calendly.isEmpty() ||
$Calendly.indexOf(" ") == 1
)
https://calendly.com/welcome-to-bench/account-check-in##
#else
#set( $Calendly = $Calendly.trim() )
$display.capitalize( $Calendly.toLowerCase() )##
#end‍‍‍‍‍‍‍‍‍‍

Note how there are spaces inside the parens. That's totally fine (and necessary to stay sane when coding) because it's not printable.

Translate