SOLVED

Re: Dates in Velocity Scripting - Anomalous Behavior

Go to solution
Vidhi_Kare
Level 3

Dates in Velocity Scripting - Anomalous Behavior

Hi Everyone,

 

Hope your week has started well.

I just came across a situation where  the  below script is running into error for a specific date but it is fine for other dates.

Example: When the leadcapturedate i.e. my object is having value '2021-09-03' or value = '2022-05-21' it is working fine, but when the object had value -'2022-05-29', it failed. 

2. Also, may I know if this is the right way to display date in single digit in my code below in line #3 .for example date is 2021-09-03 then it is displaying 3 September 2021, which is what I want. But just wanted to confirm.

**** Code****

#set($myCal = $convert.toCalendar(${convert.parseDate(${lead.as_leadcapturedate},'yyyy-MM-dd')}))
#set($calConst = $field.in($myCal))
#set($FRIENDLY_24H_DATETIME_WITH_FRIENDLY_TZ ='d MMMM yyyy')
$myCal.add($calConst.DATE,30)
${date.format($FRIENDLY_24H_DATETIME_WITH_FRIENDLY_TZ,$myCal)}

Any inputs in this regard will be appreciated.

 

Kind Regards,

Vidhi

2 ACCEPTED SOLUTIONS

Accepted Solutions
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Dates in Velocity Scripting - Anomalous Behavior

Can you try using below velocity script instead? Change the time zone as per your preference, refer IANA time zone directory for the time zone abbreviations.

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

#set($dateIn = $convert.parseDate(
  $lead.as_leadcapturedate,
  $ISO8601DateOnly,
  $defaultLocale,
  $defaultTimeZone
))

#set($dateOut = $date.format(
  "d MMMM yyyy",
  $dateIn,
  $defaultLocale,
  $defaultTimeZone
))
${dateOut}

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Dates in Velocity Scripting - Anomalous Behavior


However, not too sure what happens to the token as I did not debug the step by step code but , it flashes error on email while rendering the same token for the date ''2022-05-29" . Perhaps, I would need to add code to handle the null value in the script.


You should always be aware of the possibility of null values, but there’s no reason to expect a null here if the date is non-empty and formatted correctly.

 

Is this a true Date field in Marketo, or a String field that happens to be filled with a date-like ISO 8601 value?

View solution in original post

6 REPLIES 6
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Dates in Velocity Scripting - Anomalous Behavior

Can you try using below velocity script instead? Change the time zone as per your preference, refer IANA time zone directory for the time zone abbreviations.

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

#set($dateIn = $convert.parseDate(
  $lead.as_leadcapturedate,
  $ISO8601DateOnly,
  $defaultLocale,
  $defaultTimeZone
))

#set($dateOut = $date.format(
  "d MMMM yyyy",
  $dateIn,
  $defaultLocale,
  $defaultTimeZone
))
${dateOut}
SanfordWhiteman
Level 10 - Community Moderator

Re: Dates in Velocity Scripting - Anomalous Behavior


I just came across a situation where  the  below script is running into error for a specific date but it is fine for other dates.

Example: When the leadcapturedate i.e. my object is having value '2021-09-03' or value = '2022-05-21' it is working fine, but when the object had value -'2022-05-29', it failed. 


What do you mean, exactly, by “it is working” vs. “it failed”? Always need details for this kind of question.

Vidhi_Kare
Level 3

Re: Dates in Velocity Scripting - Anomalous Behavior

Hi Everyone,

Apologies for the delayed response.

@SanfordWhiteman : Sorry for not providing detailed explanation regarding the behaviour that I noticed in the token code working.

For Example: When the token received a date '2021-09-03' or value = '2022-05-21' then it is able to render the code in email where it is used and desired output is displayed.

However, not too sure what happens to the token as I did not debug the step by step code but , it flashes error on email while rendering the same token for the date ''2022-05-29" . Perhaps, I would need to add code to handle the null value in the script.

Also this date value is coming in Marketo from lead object field from our CRM database.

It sounds little odd but I will spend some more time in the step by step debugging of existing code.

The token code is fetching value for the field 'leadcapturedate' and after parsing , it is adding 30 days more to display the desired date in our email.

#set($myCal = $convert.toCalendar(${convert.parseDate(${lead.as_leadcapturedate},'yyyy-MM-dd')}))
#set($calConst = $field.in($myCal))
#set($FRIENDLY_24H_DATETIME_WITH_FRIENDLY_TZ ='d MMMM yyyy')
$myCal.add($calConst.DATE,30)
${date.format($FRIENDLY_24H_DATETIME_WITH_FRIENDLY_TZ,$myCal)}

 

 

Kind Regards,

Vidhi

SanfordWhiteman
Level 10 - Community Moderator

Re: Dates in Velocity Scripting - Anomalous Behavior


However, not too sure what happens to the token as I did not debug the step by step code but , it flashes error on email while rendering the same token for the date ''2022-05-29" . Perhaps, I would need to add code to handle the null value in the script.


You should always be aware of the possibility of null values, but there’s no reason to expect a null here if the date is non-empty and formatted correctly.

 

Is this a true Date field in Marketo, or a String field that happens to be filled with a date-like ISO 8601 value?

Vidhi_Kare
Level 3

Re: Dates in Velocity Scripting - Anomalous Behavior

Hi @SanfordWhiteman ,

Thank you for your reply. I totally agree to always taking care of the null value scenarios.

The field is a True Date in Marketo. But yeah, with this case, it is little weird that only for this member record, the script is not working fine.

 

Kind Regards,

Vidhi

Vidhi_Kare
Level 3

Re: Dates in Velocity Scripting - Anomalous Behavior

Hi Everyone,

 

Sorry, Actually we have some different problem in our instance while merging opportunity data with member record due to which the member lead record was not having the value in the field and hence script did not work.

But appreciate the help and inputs.

Not too sure which solution to mark as correct but thanks to @Darshil_Shah1 and @SanfordWhiteman 

Kind Regards,

Vidhi