AnsweredAssumed Answered

List based on updated date

Question asked by Michael McGowan on Aug 14, 2019
Latest reply on Aug 21, 2019 by Michael McGowan

This is a continuation of a post that was answered here: https://nation.marketo.com/thread/51108-creating-a-list-based-on-parameters-and-date

 

I am now trying to create code that creates a list of only activities completed in the current month.

 

I started by setting up the time and timezones explained in Sanford's article here:

Velocitips: Switch email content based on day/time 
and changing the format of the objects table column UpdatedAt as explained in the article here.
https://nation.marketo.com/message/198187-velocity-time-formatting-right-formatting-wrong-date

 

I see that the code is returning the values that I want for comparing the date (i.e. 2019-08) but when I changed the "If" statement on line 45, and preview the email using addresses I know completed and activity this month, I find that it is working on some profiles but not all and cannot figure out why. Any suggestions? 

##Setting times and format
#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( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )
##Getting the current month
#set( $theCurrentMonth =
${date.format( "yyyy-MM",
$calNow,
$defaultLocale,
$defaultTimeZone
)})
##Changing the format of the date in the UpdatedAt column from the objects table
#set( $dateOptions = {
"formats" : {
"userin" : "yyyy-MM-dd HH:mm:ss",
"userout" : "yyyy-MM"
},
"timezones" : {
"userin" : "America/New_York",
"userout" : "America/New_York"
},
"locale" : $date.getLocale()
} )
##Getting the Updated date and putting it into the same format as the current month
#set( $updatedDate = ${sPAdActivity_cList.get(0).updatedAt} )
#set ( $formattedUpdatedDateIn = $convert.parseDate(
$updatedDate,
$dateOptions.formats.userin,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userin)
) )
#set( $UpdatedDate_formatted = $date.format(
$dateOptions.formats.userout,
$$formattedUpdatedDateIn,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userout)
) )
## filter sorted list into new list
#set( $completedActivityList = [] )
#foreach( $activity in $sorter.sort($sPAdActivity_cList, ["updatedAt:desc"]) )
##Getting the Completed activities that were updated this month
#if( $activity.activityStatus.equals("Completed") && $UpdatedDate_formatted.equals(${theCurrentMonth}) )
#set( $void = $completedActivityList.add($activity) )
#end
#end
#if( !$completedActivityList.isEmpty() )
#set( $alternateRowColors = ["#e6eff8", "#ffffff"] )
#set( $totalPoints = $math.getTotal( $completedActivityList, "points" ) )
## open <table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #000">
<tr>
<td bgcolor="#005daa" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; color:#fff; padding-top:5px; padding-bottom:5px;"><strong>Activity</strong></td>
<td bgcolor="#005daa" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; color:#FFF; padding-top:5px; padding-bottom:5px;"><strong>Points Earned</strong></td>
</tr>
## iterate filtered list
#foreach( $activity in $completedActivityList )
#set( $rowColor = $alternateRowColors[$math.mod($foreach.index,2)] )
<tr>
<td bgcolor="${rowColor}" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; color:#000; padding-top:5px; padding-bottom:5px;">${activity.description}</td>
<td bgcolor="${rowColor}" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; color:#000; padding-top:5px; padding-bottom:5px;">${activity.points}</td>
</tr>
#end
## close </table>
<tr>
<td bgcolor="#005daa" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; padding-top:5px; padding-bottom:5px; color:#fff;"><strong>Total Points Earned</strong></td>
<td bgcolor="#005daa" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; color:#fff; padding-top:5px; padding-bottom:5px;"><strong>$totalPoints</strong></td>
</tr>
</table>
#end

Outcomes