SOLVED

date field with custom object to add if loop

Go to solution
Harry_Rashid
Level 3

Re: date field with custom object to add if loop

 

That did work but the wrong date came up:

  19 April 2021 03:00 PM

for that eventid number it should be

  17 February 2021 3:00 PM

 

See screen grab which shows what I am trying to do.

Latest code:

## get the size of the list of Custom object
## remove one from the size of the list to reference the right object in the array (arrays start at zero, not 1)
#set( $lastIndex = $math.sub($listlength,1) )
## convert the Service Start Date string to a date
#set( $dateOptions = {
"formats" : {
"userin" : "yyyy-MM-dd hh:mm",
"userout" : "dd MMMM yyyy hh:mm a"
},
"timezones" : {
"userin" : "America/Chicago",
"userout" : "Europe/London"
},
"locale" : $date.getLocale()
} )
#set( $eventdatetimelike = $oN24Attendee_cList.get($lastIndex).eventdatetime )
#set( $eventdatetime = $convert.parseDate(
$eventdatetimelike,
$dateOptions.formats.userin,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userin)
) )
## convert the date to a different format
#set( $eventdatetime_formatted = $date.format(
$dateOptions.formats.userout,
$eventdatetime,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userout)
) )
#foreach( $event in $oN24Attendee_cList )
#if( $event.eventid.equals(2862094) )
$eventdatetime_formatted
#end
#end

 

image.png

Harry_Rashid
Level 3

Re: date field with custom object to add if loop

As you can see the from the eventid: 2862094 so the date should be 

17 February 2021 3:00 PM

 

SanfordWhiteman
Level 10 - Community Moderator

Re: date field with custom object to add if loop


As you can see the from the eventid: 2862094 so the date should be 
17 February 2021 3:00 PM

Not really, the code is doing exactly what you should expect it to do!

 

Your $eventdatetimelike variable is always built from the eventdatetime property of the last item in the list. That's how you wrote it:

#set( $eventdatetimelike = $oN24Attendee_cList.get($lastIndex).eventdatetime )

 

So that value is

2021-04-19 09:00:00

per your dump of the list.

 

If you want $eventdatetimelike, and in turn $eventdatetime, to be the date of the matching item, then you can't build it from the last item.

Harry_Rashid
Level 3

Re: date field with custom object to add if loop

Thanks Sanford, I was thinking that might be the case - any chance you can help update the code to achieve this?