SOLVED

How do I format a Custom Object Expiration Date field using Velocity Script

Go to solution
Anonymous
Not applicable

How do I format a Custom Object Expiration Date field using Velocity Script

Hello Community,

I am really on a roll with these VS questions lately. So, I have been tasked with formatting a Custom Object Date field so that it appears like January 13, 2018 instead of 2018-01-13. I tried modifying the code in red below (which I used to modify an expiration date token) by inputting "certificateExpirationDate" (see screenshot below showing the custom object date field) in place of lead.expirationDate and expirationDate, but that didn't seem to work. So, not sure what I need to do next....Please help!

#set( $dateOptions = { 

  "formats" : { 

    "userin" : "yyyy-MM-dd", 

    "userout" : "MMMM d, yyyy" 

  }, 

  "timezones" : { 

    "userin" : "America/New_York", 

    "userout" : "America/New_York" 

  }, 

  "locale" : $date.getLocale() 

} ) 

#set( $expirationDatelike = $lead.expirationDate

#set( $expirationDate = $convert.parseDate( 

  $expirationDatelike, 

  $dateOptions.formats.userin, 

  $dateOptions.locale, 

  $date.getTimeZone().getTimeZone($dateOptions.timezones.userin) 

) ) 

#set( $expirationDate_formatted = $date.format( 

  $dateOptions.formats.userout, 

  $expirationDate

  $dateOptions.locale, 

  $date.getTimeZone().getTimeZone($dateOptions.timezones.userout) 

) ) 

${expirationDate_formatted} 

pastedImage_0.png

Thank you,

Laura

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How do I format a Custom Object Expiration Date field using Velocity Script

Here, the custom object $certivicates_cList is a Java ArrayList.

$certivicates_cList[0] is an object (map) that's at the first index of the array.

If $certivicates_cList[0].certificateExpirationDate is a date-like string property of the object $certivicates_cList[0], then you have to reference that string property here (and only here):

#set( $expirationDatelike = $certivicates_cList[0].certificateExpirationDate )

Note this'll only work if the lead has at least one "Certificate" record. If they don't, there won't be an index [0], so Velocity will error out.

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: How do I format a Custom Object Expiration Date field using Velocity Script

Here, the custom object $certivicates_cList is a Java ArrayList.

$certivicates_cList[0] is an object (map) that's at the first index of the array.

If $certivicates_cList[0].certificateExpirationDate is a date-like string property of the object $certivicates_cList[0], then you have to reference that string property here (and only here):

#set( $expirationDatelike = $certivicates_cList[0].certificateExpirationDate )

Note this'll only work if the lead has at least one "Certificate" record. If they don't, there won't be an index [0], so Velocity will error out.

Anonymous
Not applicable

Re: How do I format a Custom Object Expiration Date field using Velocity Script

Thank you Sanford!

I've come across some people who (for some reason) don't have an Expiration Date...Is there a logic formula that I would apply to the VS (for both a token and a custom object) for those with no Expiration Date?

Best regards,

Laura