date field with custom object to add if loop | Community
Skip to main content
New Participant
March 16, 2021
Solved

date field with custom object to add if loop

  • March 16, 2021
  • 1 reply
  • 4011 views

I have the following code, which formats date exactly the way I need it.

The issue is I only want to show the date in email which matches correct $eventid for customers.

 

I tried this loop but nothing populates:

 

#foreach( $eventid in $oN24Attendee_cList ) #if( $eventid.equals("2862094") ) $eventdatetime_formatted #end #end

----------------

Full 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( $eventid in $oN24Attendee_cList ) #if( $eventid.equals("2862094") ) $eventdatetime_formatted #end #end
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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

17 February 2021 3:00 PM

 



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.

1 reply

SanfordWhiteman
New Participant
March 17, 2021

In this loop...

#foreach( $eventid in $oN24Attendee_cList ) #if( $eventid.equals("2862094") ) $eventdatetime_formatted #end #end

... you're comparing the entire (Map) object $eventid to the value "2862094".

 

That's not what you want. You should be comparing the value of a particular key in the object to your target string, i.e.

#foreach( $event in $oN24Attendee_cList ) #if( $event.eventid.equals("2862094") ) $eventdatetime_formatted #end #end

 

(I used eventid as a placeholder. Not sure what the key is in your case, you'd know that by dragging the field onto the canvas.)

HaroonRaAuthor
New Participant
March 17, 2021

Hi Sanford,

Thanks for the help but when I add in the formatted field $eventdatetime_formatted within that loop nothing shows up(only blank space). The field I am targeting is eventid ${oN24Attendee_cList.get(0).eventid}.

 

I used your code but it still shows blank.

SanfordWhiteman
New Participant
March 17, 2021
Please show the output of the entire list (unfiltered).