SOLVED

Velocity Scripting - make lowercase

Go to solution
Anonymous
Not applicable

Velocity Scripting - make lowercase

Hi,

So I wrote the following velocity script to make a token value to appear in lower case in the email copy:

1. #set ($ptier = ${lead.Partner_Tier__c.toLowerCase()})

    $display.capitalize($ptier)

  Am using this as a token {{my.Previous_Partner_Tier1}} in my email copy.

2. #set ($pptier = ${lead.Previous_Partner_Tier__c.toLowerCase()})

   $display.capitalize($pptier)

  Token that I am using in email copy {{my.Previous_Partner_Tier1}}

Yesterday - I did couple of sample tests of the email and it all worked fine.

Today its not working, the tokens are not getting populated with value and are appearing as {{my.Previous_Partner_Tier1}} in the copy itself. Would you know if anything has changed in the velocity email scripting side that I need to update in the script above? or am I missing something?

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Velocity Scripting - make lowercase

So here is whats worked for me:

To make a value lowercase and capitalize the first word, you can use the velocity scripting as below:

    #set ($ptier = ${lead.Partner_Tier__c.toLowerCase()})

    $display.capitalize($ptier)

Note:

* The email preview shows you the token (i.e {{my.Previous_Partner_Tier1}}), rather than the value

* Setting up default value for the velocity token resulted in errors, so I haven't put one in

* You can do sample send, but better to test it by doing a email send using a smart campaign and I could see the values populated accurately.

* One prob is that I can see a "space" in the email copy next to wherever the values are now - which needs to be "trimmed". I'll update you if I am able to resolve this one.

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - make lowercase

First, your code isn't doing what you're saying it's doing.  It's not lowercasing, it's lowercasing and then capitalizing the first letter.

Second, you're saying you've named the two Velocity scripts the same: {{my.Previous_Partner_Tier1}}. This is not possible. The same name cannot refer to two scripts at the same time. If you're overriding the token at a lower level of the tree, that's still only one available script by that name.

(Also, don't use ${formal} syntax in #set statements unless you need to. Makes the code harder to read. And please use the code highlighting/formatting ability of this forum.)

Anonymous
Not applicable

Re: Velocity Scripting - make lowercase

Yes, thats what I want it to do, make the value lowercase and then capitalize first letter.

Sorry, posted this message quickly so pasted token names as the same - but in my marketo program the velocity script are correctly entered and they do have different names: 1. my.Partner_Tier1 and 2. my.Previous_Partner_Tier1

If anyone has done this before and your script has worked, please let me know? Reply with your script so I can see - thanks

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - make lowercase

#set( $ptier = $display.capitalize( $lead.Partner_Tier__c.toLowerCase() ) )

${ptier}

However, I suspect the problem isn't with your code (which is effectively the same as the above) but how you're testing.  Send yourself a real email, not a sample.

Anonymous
Not applicable

Re: Velocity Scripting - make lowercase

This code renders into error when used as a token:

  1. #set( $ptier = $display.capitalize( $lead.Partner_Tier__c.toLowerCase() ) ) 
  2. ${ptier} 

Anonymous
Not applicable

Re: Velocity Scripting - make lowercase

So here is whats worked for me:

To make a value lowercase and capitalize the first word, you can use the velocity scripting as below:

    #set ($ptier = ${lead.Partner_Tier__c.toLowerCase()})

    $display.capitalize($ptier)

Note:

* The email preview shows you the token (i.e {{my.Previous_Partner_Tier1}}), rather than the value

* Setting up default value for the velocity token resulted in errors, so I haven't put one in

* You can do sample send, but better to test it by doing a email send using a smart campaign and I could see the values populated accurately.

* One prob is that I can see a "space" in the email copy next to wherever the values are now - which needs to be "trimmed". I'll update you if I am able to resolve this one.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - make lowercase

#set ($ptier = ${lead.Partner_Tier__c.toLowerCase()})

$display.capitalize($ptier)

The curly braces are extraneous in #set.

* The email preview shows you the token (i.e {{my.Previous_Partner_Tier1}}), rather than the value

You have to set up a test list, then you can view rendered tokens in preview.

Look in the upper-left-hand side of the preview window.

* One prob is that I can see a "space" in the email copy next to wherever the values are now - which needs to be "trimmed". I'll update you if I am able to resolve this one.

Of course there's a space. Velocity is whitespace-preserving.  You have to end output with a ## to remove spaces, including newlines.

${ptier}##

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - make lowercase

The line numbers aren't part of the code.

The code is fine.

Anonymous
Not applicable

Re: Velocity Scripting - make lowercase

Hey Sanford - nope, I didn't use the numbers in the code.

I am testing trim function to get rid of white space, but yes, like you say ## could also work, similar to doing java scripting.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - make lowercase

My code is fine.

String::trim() will be of no use to you. You are still adding whitespace at the end of the output.