SOLVED

Velocity script adding a space before my URL

Go to solution
Eoin_Lyons1
Level 2

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
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script adding a space before my URL

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.

View solution in original post

11 REPLIES 11
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script adding a space before my URL

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

Eoin_Lyons1
Level 2

Re: Velocity script adding a space before my URL

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script adding a space before my URL

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.

Eoin_Lyons1
Level 2

Re: Velocity script adding a space before my URL

This was really helpful and the code worked, thanks for your help on this!

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script adding a space before my URL

OK, mark as Correct if you can, thanks!

Katie_Owens
Level 1

Re: Velocity script adding a space before my URL

I've got a similar problem Sanford Whiteman, a space is always added after the scripted token - can you see any reason why? 

#if( ${OpportunityList.get(0).Account_Owner_Phone__c} )
${OpportunityList.get(0).Account_Owner_Phone__c}
#else
1-877-000-0000
#end‍‍‍‍‍‍‍‍‍‍
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script adding a space before my URL

Make sure there aren't any trailing spaces on line 2 or line 4, and that there aren't extra blank lines after what you've posted.

Katie_Owens
Level 1

Re: Velocity script adding a space before my URL

No extra spaces in the script, but the extra space after is something that we see in practically every scripted token we use. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script adding a space before my URL

So are there any blank lines at the end (those are line breaks, which HTML prints as a space)?