A Few More Email Scripting Examples

Anonymous
Not applicable

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

4395
12
12 Comments
Grégoire_Miche2
Level 10

Thx a lot Kristen.

-Greg

Jason_Hamilton1
Level 8 - Champion Alumni

Awesome, thanks Kristen

Valerie_Armstro
Level 10 - Champion Alumni

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!

Jason_Hamilton1
Level 8 - Champion Alumni

Hi Valerie,

Try this

#set($dateInXDays = $date.calendar)

$dateInXDays.add(10,336)

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

Valerie_Armstro
Level 10 - Champion Alumni

Jason Hamilton​ - it works!  Thank you so much

Jason_Hamilton1
Level 8 - Champion Alumni

Glad I could help

Anonymous
Not applicable

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)

Anonymous
Not applicable

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.

JD_Nelson
Level 10 - Community Advisor

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?

SanfordWhiteman
Level 10 - Community Moderator

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