Re: #foreach Not Looping/Triggering?

nhabischWings
Level 5

#foreach Not Looping/Triggering?

Hello,
Not sure if I am missing something - but I seem to be running into a weird issue. My original script is as follows:

 

 

##Standard Velocity Date/Time Fields
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Chicago") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
##Set blank array for future values
#set( $fullNames = [] )
##iterate Customer Profile records and set Membership Opening Date to usable value for script
#foreach ( $item in $customerProfilesList )
#set( $membershipOpeningDate = $convert.parseDate(
    $item.membershipDate,
    $ISO8601DateOnly, 
    $defaultLocale, 
    $defaultTimeZone 
) )
##Sets difference from Membership Opening Date between -3 and 0 days
#set( $pastDiff = -3 )
#set( $currentDiff = 0 )
#set( $diffDays = $date.difference($calNow,$membershipOpeningDate).getDays().intValue() )
#set( $acceptableDiffs = [$pastDiff..$currentDiff] )
##Checks if qualifying Lead is a Member and a Person
#if ( ( $acceptableDiffs.contains($diffDays) ) && ($item.membershipStatus.equals("Member")) && ($item.customerType.equals("PERSON")) )
#set ( $void = $fullNames.add($item.fullName) )
#else
#end
#end
##Display full names that meet conditional in clean formatting
${display.list($fullNames)}

 

This works great in most cases - but one thing I'm running into is certain Leads seem to not activate/work with the script? I've got a Lead where there is 5 records to be looped through, with only 1 qualifying for the above script - but the output is my else so nothing.

Where it gets weird is that if I run a basic print script like the below - nothing gets output.

 

#foreach ( $item in $customerProfilesList )
$item.fullName
#end

Yes, I have the correct fields checked and such - and yes there is applicable data in the fields of the records. Both of the above work great for single-record cases, but it's weird. Even for the basic #foreach print test - for the object that has multiple records that all have a Full Name value - it's not printing anything.

Am I missing something very basic here? 

 

14 REPLIES 14
SanfordWhiteman
Level 10 - Community Moderator

Re: #foreach Not Looping/Triggering?

Please show the raw output of the list for a case where it doesn't seem to iterate.

 

Debugging always starts with looking at raw data.

${customerProfilesList}

 

nhabischWings
Level 5

Re: #foreach Not Looping/Triggering?

Hmm interesting, so if I pull that on the CO with one record it pulls correctly:


But when I run it one the Lead with multiple records, I just get the below - doesn't even print the raw output 

 

 

${customerProfilesList}

 

 


Seems like it only occurs on some - here's one where multiple records render correctly:

 

 

 

*Removing member data for now*

SanfordWhiteman
Level 10 - Community Moderator

Re: #foreach Not Looping/Triggering?

Are these Marketo Custom Objects or SFDC COs?
nhabischWings
Level 5

Re: #foreach Not Looping/Triggering?

Marketo - we do not (currently) use SDFC.

SanfordWhiteman
Level 10 - Community Moderator

Re: #foreach Not Looping/Triggering?

Please show the Custom Objects tab for the person who doesn't work, then. Make sure the screenshot shows every record.
nhabischWings
Level 5

Re: #foreach Not Looping/Triggering?

*Removing data for now*

SanfordWhiteman
Level 10 - Community Moderator

Re: #foreach Not Looping/Triggering?

Can you access each item directly using its index?
nhabischWings
Level 5

Re: #foreach Not Looping/Triggering?

Doing something like:

${customerProfilesList.get(0).fullName}

Is still only bringing back the above and not a value.

SanfordWhiteman
Level 10 - Community Moderator

Re: #foreach Not Looping/Triggering?

For every item?