So I have a custom list (account_cList).
I want it to check if ${account_cList.get(0).productType} has one of the qualifying (integer) values:
1001, 1002, 1003, 1004, 1009, 1010, 1011, 1012, 1027, 1028, 1200, 1201, 1202, 1203, 1204, 1205, 1210, 1211, 1213, 1214, 1215
Next, I want to look at ${account_cList.get(0).openDate} (date) and see if that date is in the last 7 days
and if it has a value there, I want to take ${account_cList.get(0).autoMake} and ${account_cList.get(0).autoModel} and convert them to title case (they are all caps by default). If there is a value in both or either, i want it to just show that. if there is a value in neither of those fields, I want it to default to "new ride".
I am only able to get it to show the default (new ride), even when there are qualifying people who should have the make and model display a value. Below is the script I used.
#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( $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($validProductTypes = [1001, 1002, 1003, 1004, 1009, 1010, 1011, 1012, 1027, 1028, 1200, 1201, 1202, 1203, 1204, 1205, 1210, 1211, 1212, 1213, 1214, 1215])
## Check if productType is valid and openDate is within the last 7 days
#if($validProductTypes.contains(${account_cList.get(0).productType}))
#set($currentDate = $dateTool.now())
#set($openDate = $dateTool.parse('yyyy-MM-dd', ${account_cList.get(0).openDate}))
#set($dateDiffMillis = $dateTool.diff($currentDate, $openDate, 'days'))
#if($dateDiffMillis >= 0 && $dateDiffMillis <= 7)
## Format autoMake and autoModel with capitalized first letters
#set($make = ${account_cList.get(0).autoMake})
#set($model = ${account_cList.get(0).autoModel})
#if($string.isNotBlank($make))
#set($make = $string.capitalize($make.toLowerCase()))
#else
#set($make = "")
#end
#if($string.isNotBlank($model))
#set($model = $string.capitalize($model.toLowerCase()))
#else
#set($model = "")
#end
Open Date (Formatted): $dateTool.format('yyyy-MM-dd', ${account_cList.get(0).openDate})
#if($string.isNotBlank($make) || $string.isNotBlank($model))
#if($string.isNotBlank($make))
Make: $make
#end
#if($string.isNotBlank($model))
Model: $model
#end
#else
new ride
#end
#else
new ride
#end
#else
new ride
#end
DateTool is exported in Velocity as the variable $date
— that’s the same $date
at the top of your code. Not $dateTool
.
What a dummy... didn't see that.
I updated that, but I'm still only getting the default value. Is there anything else that is sticking out?
#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( $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($validProductTypes = [1001, 1002, 1003, 1004, 1009, 1010, 1011, 1012, 1027, 1028, 1200, 1201, 1202, 1203, 1204, 1205, 1210, 1211, 1212, 1213, 1214, 1215])
## Check if productType is valid and openDate is within the last 7 days
#if($validProductTypes.contains(${account_cList.get(0).productType}))
#set($currentDate = $date.format('yyyy-MM-dd', $date.date()))
#set($openDate = $date.parse('yyyy-MM-dd', ${account_cList.get(0).openDate}))
#set($dateDiffMillis = $date.dateDiff('d', $openDate, $currentDate))
#if($dateDiffMillis >= 0 && $dateDiffMillis <= 7)
## Format autoMake and autoModel with capitalized first letters
#set($make = ${account_cList.get(0).autoMake})
#set($model = ${account_cList.get(0).autoModel})
#if($string.isNotBlank($make))
#set($make = $string.capitalize($make.toLowerCase()))
#else
#set($make = "")
#end
#if($string.isNotBlank($model))
#set($model = $string.capitalize($model.toLowerCase()))
#else
#set($model = "")
#end
Open Date (Formatted): $date.format('yyyy-MM-dd', $openDate)
#if($string.isNotBlank($make))
$make
#end
#if($string.isNotBlank($model))
#if($string.isNotBlank($make))
$model
#else
$model
#end
#end
#if($string.isBlank($make) && $string.isBlank($model))
new ride
#end
#else
new ride
#end
#else
new ride
#end
You were calling a couple of nonexistent methods in there — make sure to use the DateTool/ComparisonDateTool docs. Plus constantly dereferencing the first Account was giving me a headache!
#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( $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($validProductTypes = [1001, 1002, 1003, 1004, 1009, 1010, 1011, 1012, 1027, 1028, 1200, 1201, 1202, 1203, 1204, 1205, 1210, 1211, 1212, 1213, 1214, 1215])
#set( $focusedAccount = $account_cList.get(0) )
#set( $openDate = $convert.parseDate($focusedAccount.openDate, 'yyyy-MM-dd' ) )
#set( $productType = $focusedAccount.productType )
#set( $dateDiffDays = $date.whenIs($openDate).getDays() )
## Check if productType is valid and openDate is within the last 7 days
#if( $validProductTypes.contains($productType) && $dateDiffDays <= 0 && $dateDiffDays >= -7 )
## Format autoMake and autoModel with capitalized first letters
#set($make = $focusedAccount.autoMake)
#set($model = $focusedAccount.autoModel)
#if($string.isNotBlank($make))
#set($make = $string.capitalize($make.toLowerCase()))
#else
#set($make = "")
#end
#if($string.isNotBlank($model))
#set($model = $string.capitalize($model.toLowerCase()))
#else
#set($model = "")
#end
Open Date (Formatted): $date.format('yyyy-MM-dd', $openDate)
#if($string.isNotBlank($make))
$make
#end
#if($string.isNotBlank($model))
#if($string.isNotBlank($make))
$model
#else
$model
#end
#end
#if($string.isBlank($make) && $string.isBlank($model))
new ride
#end
#else
new ride
#end