Velocity Script - to add 30 minutes in the Meeting time | Community
Skip to main content
New Participant
May 1, 2021
Question

Velocity Script - to add 30 minutes in the Meeting time

  • May 1, 2021
  • 1 reply
  • 2136 views

Hey,

 

I want to display Meeting StartTime and End time (Total Meeting time is 30 minutes) like Tuesday, May 18, 10:00 -- 10:30 am EDT

The field I am using is 'Appointment_Start_DateTime_Text__c' (DataType = Text).

 

The value of the 'Appointment_Start_DateTime_Text__c' is '05/03/2021 10:00:00 AM EDT'

#foreach($obj in $sorter.sort($Activity_Marketo__cList , "CreatedDate__c:desc")) #set($Appointment_Start = $date.toDate("MM/dd/yyyy hh:mm:ss a", $obj.Appointment_Start_DateTime_Text__c)) #set($dateFormatted = $date.format("EEEE, MMM. dd", $Appointment_Start)) #set($salutationdate = $date.format("MMMM d", $Appointment_Start)) #set($dateFormattedHours = $date.format("hh:mm a", $Appointment_Start)) #set($FormattedStartDate = $date.format("EEEEE, MMMM d,", $Appointment_Start)) #set($FormattedStartTime = $date.format("h:mm", $Appointment_Start)) ## EndTime ## #set($FormattedEndTime1 = $Appointment_Start.calendar) #set($FormattedEndTime = $FormattedEndTime1.add(12,30)) ## EndTime ## #set($AMPM = $date.format("a", $Appointment_Start)) ## TimeZone ## #set ($Appointment = "$obj.Appointment_Start_DateTime_Text__c") #set ($stringLength = $obj.Appointment_Start_DateTime_Text__c.length() - 0) #set ($AppointmentTimeZone = $Appointment.substring(23,$stringLength)) ## TimZone ## $FormattedStartDate $FormattedStartTime -- $FormattedEndTime $AMPM.toLowerCase() $AppointmentTimeZone #break #end

The Output is --> Monday, May 3, 10:00 -- $FormattedEndTime am EDT

 

Can any one help me ASAP what is wrong in the EndTime script.

Thanks in advanced!

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

1 reply

SanfordWhiteman
New Participant
May 2, 2021

A number of guesses make your code pretty hard to interpret — you're calling methods and accessing properties that simply don't exist.

 

Every time you do that, Java throws a fatal error.  Velocity isn't showing you the errors (because it's being polite) but if you check the return value you'll see it's null.

 

For example:

  • Date objects don't have an add method.
  • Date objects don't have a calendar property.

Guesswork just... won't work. 🙂

 

To add time to a Calendar object, you use Calendar.add. An example is in the section "PROMO EXPIRES 7 DAYS FROM TODAY" in this post: https://blog.teknkl.com/velocity-days-and-weeks/.

 

Also, what you're doing with time zones concerns me a lot; it's far too fragile to put in production code. When a Date-Like String contains a time zone, you should parse the Time Zone (code z/Z in a SimpleDateFormat) as part of creating the real Date object, using the built-in parser. Don't just split the string.

 

New Participant
May 4, 2021

Hey @sanfordwhiteman  Thanks for the response 🙂

 

I am able to fetch the End time using the below script:

## EndTime ## #set( $myCal = $convert.toCalendar($Appointment_Start)) $myCal.add(12,30) #set($FormattedEndTime = $date.format("h:mm", $myCal.time)) ## EndTime ##

 

Regarding the TimeZone, I will received multiple timezone as per the different Meetings of people. So if I will try to fetch through DateFormat it will convert into Marketo default CST/CDT timezone.

And I want to use the same Meeting TimeZone which I received for each records in the email as well not the converted CST/CDT or any specific timezone. Due to that reason I have split the String from the Text field.