SOLVED

date field with custom object to add if loop

Go to solution
Harry_Rashid
Level 3

date field with custom object to add if loop

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
1 ACCEPTED SOLUTION

Accepted Solutions
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.

View solution in original post

13 REPLIES 13
SanfordWhiteman
Level 10 - Community Moderator

Re: date field with custom object to add if loop

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.)

Harry_Rashid
Level 3

Re: date field with custom object to add if loop

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
Level 10 - Community Moderator

Re: date field with custom object to add if loop

Please show the output of the entire list (unfiltered).
Harry_Rashid
Level 3

Re: date field with custom object to add if loop

Harry_Rashid_0-1615980886635.png

This is the field I am trying use to filter correct data into the email, what needs to show after data format complete:

Harry_Rashid_1-1615980944486.png

this is what is showing at moment, but is from another record in custom object for that customer

19 April 2021 03:00 PM

fields that are used:

${oN24Attendee_cList.get(0).eventdatetime}
${oN24Attendee_cList.get(0).eventid}
${oN24Attendee_cList.get(0).eventtitle}
Harry_Rashid
Level 3

Re: date field with custom object to add if loop

I think its to do with the IF loop, seems to go blank when adding that within the FOR loop.

SanfordWhiteman
Level 10 - Community Moderator

Re: date field with custom object to add if loop


I think its to do with the IF loop, seems to go blank when adding that within the FOR loop.

(#if isn't a loop, it's just a condition. #foreach is your loop.)

SanfordWhiteman
Level 10 - Community Moderator

Re: date field with custom object to add if loop

I need to see the real output (not in the UI, in Velocity) of the list variable:

${oN24Attendee_cList}

 

Harry_Rashid
Level 3

Re: date field with custom object to add if loop

Output for ${oN24Attendee_cList}

[{email=cstanton@xxxx.com, eventid=2923321, eventuserid=396136339, personid=85610818, createdAt=2020-12-14 12:14:30, updatedAt=2020-12-16 10:24:27, marketoGUID=6e1d4db5-f994-402f-8f8c-226e5df5fb1d, answeredsurveys=1, archiveminutes=0, askedquestions=1, attendedarchive=N, attendedlive=Y, engagementscore=1.28, eventtitle=Dev Testing - Marketo Integration Webinar: Live Video and Audio with Screen Share, liveminutes=0, userprofileurl=null, country=null, eventurl=https://event.on24.com/wcc/r/2923321/8E5C6E8A24121312C6E9ECEEDC0797A0, firstname=Christopher, lastname=Stanton, mktpermissions=null, partner_ref=element14, eventdatetime=null}, 

{email=cstanton@xxxx.com, eventid=2971146, eventuserid=403064471, personid=85610818, createdAt=2021-01-15 10:59:18, updatedAt=2021-01-15 13:02:15, marketoGUID=eca41fd8-ce1b-40ad-878f-4bc7125bb57a, answeredsurveys=0, archiveminutes=0, askedquestions=0, attendedarchive=N, attendedlive=Y, engagementscore=0.9, eventtitle=Dev Testing - Marketo Integration Webinar: Live Video and Audio with Screen Share - 5, liveminutes=12, userprofileurl=null, country=null, eventurl=https://event.on24.com/wcc/r/2971146/D8337458BB173CD29D78A2207CEA83ED, firstname=Christopher, lastname=Stanton, mktpermissions=null, partner_ref=null, eventdatetime=null}, 

{email=cstanton@xxxx.com, eventid=2862094, eventuserid=412031846, personid=85610818, createdAt=2021-02-11 10:17:22, updatedAt=2021-02-11 10:17:22, marketoGUID=5defefde-ba8a-44e1-a441-56870c46eb9a, answeredsurveys=null, archiveminutes=null, askedquestions=null, attendedarchive=null, attendedlive=null, engagementscore=null, eventtitle=How Will Industry 4.0 and IIoT Change Manufacturing?, liveminutes=null, userprofileurl=null, country=null, eventurl=https://event.on24.com/wcc/r/2862094/E6DF1C914D7E0531E26C4F20D1CFCBAB, firstname=Christopher, lastname=Stanton, mktpermissions=null, partner_ref=element14, eventdatetime=2021-02-17 09:00:00}, 

{email=cstanton@xxxx.com, eventid=3009982, eventuserid=412753872, personid=85610818, createdAt=2021-02-15 09:00:38, updatedAt=2021-02-15 09:00:38, marketoGUID=f006766f-6df6-48f6-941d-99d38b431cdc, answeredsurveys=null, archiveminutes=null, askedquestions=null, attendedarchive=null, attendedlive=null, engagementscore=null, eventtitle=Thunderboard Workshop: Industrial-Grade TinyML Applications with Silicon Labs and Edge Impulse!, liveminutes=null, userprofileurl=null, country=null, eventurl=https://event.on24.com/wcc/r/3009982/25A49F43B8E20571B91468811F6A85F9, firstname=Christopher, lastname=Stanton, mktpermissions=null, partner_ref=element14, eventdatetime=2021-02-25 11:00:00}, 

{email=cstanton@xxxx.com, eventid=2989768, eventuserid=412753739, personid=85610818, createdAt=2021-02-15 09:00:38, updatedAt=2021-02-15 09:00:38, marketoGUID=5bffb342-c397-4cfd-ab75-ef155009b489, answeredsurveys=null, archiveminutes=null, askedquestions=null, attendedarchive=null, attendedlive=null, engagementscore=null, eventtitle=LPDDR4 Trends and Tech (Register to Win a Raspberry Pi 4!), liveminutes=null, userprofileurl=null, country=null, eventurl=https://event.on24.com/wcc/r/2989768/D3EE09A3DDCF112CBAC4E98F98302286, firstname=Christopher, lastname=Stanton, mktpermissions=null, partner_ref=element14, eventdatetime=2021-02-24 11:00:00}, 

{email=cstanton@xxxx.com, eventid=3053359, eventuserid=421641290, personid=85610818, createdAt=2021-03-15 12:21:51, updatedAt=2021-03-15 12:21:51, marketoGUID=f41528de-8591-4087-b02c-78e6f3f2d20c, answeredsurveys=null, archiveminutes=null, askedquestions=null, attendedarchive=null, attendedlive=null, engagementscore=null, eventtitle=IoT MythBusters: Tomorrow's Future Today, liveminutes=null, userprofileurl=null, country=null, eventurl=https://event.on24.com/wcc/r/3053359/17BCF76DEE585B7D8BEADC685766177E, firstname=Christopher, lastname=Stanton, mktpermissions=null, partner_ref=element14, eventdatetime=2021-04-19 09:00:00}]

$eventdatetime_formatted
SanfordWhiteman
Level 10 - Community Moderator

Re: date field with custom object to add if loop

Are you sure eventid is a String?

 

You're comparing it with a String:

.equals("2862094")

 

if it's a Number, you need to compare it accordingly:

.equals(2862094)