Skip to main content
Mar 22, 2016 11:09 PM UTC

A Few More Email Scripting Examples

I wanted to share a few more email scripting examples with you.

Example 1: This script lowercases a string (in this case First and Last Name) and then properly capitalizes it.

(I think the previous example I gave only capitalizes the first letter, so if you had mixed case or all capitalized letters, it is not as good as this one.)

#set ($fname = ${lead.FirstName.toLowerCase()})

#set ($lname = ${lead.LastName.toLowerCase()})

$display.capitalize($fname) $display.capitalize($lname)

Example 2: This script adds a date 14 days in the future onto a token being used in an email.

## Access Velocity's calendar object

#set($x = $date.calendar)

## Format date

#set($current_date = $date.full_date)

## Add 24 hours (hours=int code 10 - see list below)

$x.add(6,14)

## Show result

$current_date

Example 3: This script gets the current date from the calendar object, converts it to a date and then reformats it to the format highlighted in yellow.

#set ( $todayCalObj = $date.toCalendar($date.toDate("yyyy-MM-dd H:m:s",$date.get('yyyy-MM-dd H:m:s'))) )

#set ( $dateObj = $date.toDate("yyyy-MM-dd", $todayCalObj) )

#set($dateFormatted = $date.format("MM/dd/yyyy", $dateObj))

$dateFormatted

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

12 replies

Grégoire_Miche2
Level 10
Mar 22, 2016 11:14 PM UTC

Thx a lot Kristen.

-Greg

Translate
Jason_Hamilton1
Level 6
Mar 22, 2016 11:48 PM UTC

Awesome, thanks Kristen

Translate
Valerie_Armstro
Level 9
May 3, 2016 6:15 PM UTC

Hi Kristen Carmean - I'm looking to use the example you provided for the date 14 days in the future, but having some trouble getting it to work properly.  Currently, it keeps returning today's date instead of one 14 days out.  Is there something I am suppose to be changing in the code you provided?  Thanks!

Translate
Jason_Hamilton1
Level 6
May 3, 2016 6:51 PM UTC

Hi Valerie,

Try this

#set($dateInXDays = $date.calendar)

$dateInXDays.add(10,336)

$date.format('full_date',$dateInXDays.time)

Translate
Valerie_Armstro
Level 9
May 3, 2016 8:41 PM UTC

@Jason Hamilton​ - it works!  Thank you so much

Translate
Jason_Hamilton1
Level 6
May 4, 2016 1:48 AM UTC

Glad I could help

Translate
Jun 3, 2016 2:50 PM UTC

I am trying use same logic for field of lead object rather than current date from calender, apparently it did not work any insight?

my script is like this

#set($dateInXDays = ${lead.Appointment})

$dateInXDays.add(10,24)

$date.format('full_date',$dateInXDays.time)

Translate
Jun 3, 2016 3:54 PM UTC

I believe you need to change the lead field into a calendar object. You see how in the example scripts, you do the $date.calendar? That's what this part is doing. So you are missing the step of converting your dateTime format into a calendar.

Translate
Community Advisor
Feb 21, 2017 10:47 PM UTC

Hi Kristen Carmean​ -- I'm a bit late to this thread, but looking to expand #3, when you reference "calendar object" is this referencing 'todays date' (I believe, yes), and/or is there a way to pull the date listed in the calendar token?

For example: We have an event that has a calendar token with a date of March 1. I want to be able to reformat that date (not today's date) in the method you've described; is that feasible?

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Feb 21, 2017 10:53 PM UTC

JD, if you search my Community posts on Velocity, you'll see several examples of this.

Translate