How do I write Velocity script using "any" or "or" conditions?
I'm trying to combine NEW Product X Trials ($lead.dMSSubscribedDate) and NEW Product X Subscriptions ($lead.dMSTrialDateTime) using "any" or "or" conditions utilizing the (||).
If a Lead's Trial OR Subscription DateTime is in past 24 hours then that New Product Trial or Subscription = TRUE and will receive the corresponding Welcome content.
I think this is an easy function within velocity based on how seamlessly the use of the "and" (&&) function was to utilize.
The challenge is writing un-broken code. I can't get the output correct.
I want to combine this 1st block with the 2nd block using the "any" or "or" (| |) logic:
#set( $ISO8601WithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Los_Angeles") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#if( !$lead.dMSTrialDateTime.isEmpty() )
#set( $caldMSTrialDateTime = $convert.toCalendar(
$convert.parseDate(
$lead.dMSTrialDateTime,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$caldMSTrialDateTime).getHours() >= -24 )
You now have access to PRODUCT X!
#end
#end#set( $ISO8601WithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Los_Angeles") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#if( !$lead.dMSSubscribedDate.isEmpty() )
#set( $caldMSSubscribedDate = $convert.toCalendar(
$convert.parseDate(
$lead.dMSSubscribedDate,
$ISO8601WithSpace,
$defaultLocale,
$defaultTimeZone
)
) )
#if( $date.difference($calNow,$caldMSSubscribedDate).getHours() >= -24 )
You now have access to PRODUCT X!
#end
#endI do know this line is correct ---
#if( $date.difference($calNow,$caldMSSubscribedDate).getHours() >= -24 || $date.difference($calNow,$caldMSTrialDateTime).getHours() >= -24 )--- however I incorrectly assumed that in every line $lead.dMSSubscribedDate and $caldMSSubscribedDate appeared (the first #if and #set lines 9-17) would require the | | followed by the trial fields $lead.dMSTrialDateTime and $caldMSTrialDateTime.