Hi there could use some help with troubleshooting some velocity script issues we are running into. We have a custom SFDC object that is related to the Person record via the account. We have checked off the fields used in the script as well as the company field. Here is the script we are trying to get to populate a date field:
## standard Velocity date/time includes
#set ($company=$lead.Company)
#set ($practice=$lead.Practice__c)
#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( $SpendReach = $Practice__cList.get(0).SPO_Start_Date__c)
## Corrected date parsing using $dateTool
#set( $dateIn = $dateTool.parseDate($SpendReach, $ISO8601DateOnly, $defaultLocale, $defaultTimeZone) )
## Corrected date formatting pattern with single quotes
#set( $dateOut = $date.format("d MMMM yyyy", $dateIn, $defaultLocale, $defaultTimeZone) )
However, in our emails it just remains blank even when sending to records that have a date. Let me know if I should add to another discussion thread.
$dateTool.parseDate
does not exist. You want $convert.parseDate
.
It’s not clear why you’re accessing the first item in the $Practice__cList
every time. That’s usually a wrong move. You should only access the first item if you’ve specifically sorted or filtered the list so a certain item is known to be at the top.
Let me know if I should add to another discussion thread.
Definitely not!
Hi Sanford, In this example the custom object only has one record for each contact so we should only need the one record (or first record) that exists. Ill make that change in the script and see if it solves the issue.
Got it, so something more along the lines like this should be expected to pull in the first value:
## standard Velocity date/time includes
#set($sortedlist = $sorter.sort($Practice__cList,"updatedAt:desc"))
#foreach($practicelist in $sortedlist)
#set ($company=$lead.Company)
#set ($practice=$lead.Practice__c)
#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( $SpendReach = $practicelist.Reached_Spend_Cap_Date__c)
## Corrected date parsing using $dateTool
#set( $dateIn = $convert.parseDate($SpendReach, $ISO8601DateOnly, $defaultLocale, $defaultTimeZone) )
## Corrected date formatting pattern with single quotes
#set( $dateOut = $date.format("d MMMM yyyy", $dateIn, $defaultLocale, $defaultTimeZone) )
$dateOut
#end
Mostly, although you shouldn't redefine these variables over and over in the loop, as their value is constant. They should be outside (before) the loop:
#set ($company=$lead.Company)
#set ($practice=$lead.Practice__c)
#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" )
Hi @SanfordWhiteman , made those changes and data was still not pulling in. I believe we found the issue. If the custom object is related to the Account but through a regular lookup relationship and not as a Master Detail relationship, could that impact the data coming through?
Well, there isn’t much room for mystery here — does the custom object list have the raw values or not?
We can see the object in the editor:
However, it is a SFDC custom object, so the raw values are not visible on the persons record details.
I’m referring to it being accessible within Velocity. Just dump the $whatever_List
.