Repost of List based on updated date

Michael_McGowa1
Level 3

Re: Repost of List based on updated date

Here it is.

#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" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

##set( $theCurrentMonth = 
##$date.format( "yyyy-MM",
##   $calNow,
##   $defaultLocale,
##  $defaultTimeZone
##))


##set( $LastWeek = 
##$date.format( "yyyy-MM",
##  $calNow.subtract($calConst.DATE,7),
##  $defaultLocale,
##  $defaultTimeZone
##) )

$calNow.add($calConst.MONTH,-1)
#set( $myLastMonth = 
$date.format( "yyyy-MM",
  $calNow,
  $defaultLocale,
  $defaultTimeZone
) )


#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()    
} )

#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"]) )
#if( $activity.activityStatus.equals("Completed") && ($UpdatedDate_formatted == $myLastMonth) )
#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( $sPAdActivity_cList.description = $myDescription.replaceAll("^${esc.q}|${esc.q}$",""))
#set( $rowColor = $alternateRowColors[$math.mod($foreach.index,2)] )
<tr>
 <td bgcolor="${rowColor}" valign="middle" style="font-family:Helvetica, sans-serif; font-size:13px; padding-left:5px; padding-right:5px; color:#000; padding-top:5px; padding-bottom:5px;">${activity.description.replaceAll("^${esc.q}|${esc.q}$","")}</td>
 <td bgcolor="${rowColor}" valign="middle" style="font-family: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: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: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
SanfordWhiteman
Level 10 - Community Moderator

Re: Repost of List based on updated date

This line isn't doing anything (you can't set properties directly on a list like $sPAdActivity_cList.description; it also refers to a nonexistent variable $myDescription and is never used again):

 

#set( $sPAdActivity_cList.description = $myDescription.replaceAll("^${esc.q}|${esc.q}$",""))

 

The second comparison in this line continually compares the same 2 variables ($UpdatedDate_Formatted is created from the first item in $sPAdActivity_cList, only once, not the current $activity in the loop):

 

#if( $activity.activityStatus.equals("Completed") && ($UpdatedDate_formatted == $myLastMonth) )