#foreach Not Looping/Triggering? | Community
Skip to main content
New Participant
May 15, 2023
Question

#foreach Not Looping/Triggering?

  • May 15, 2023
  • 1 reply
  • 3084 views

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? 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
New Participant
May 15, 2023

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}

 

New Participant
May 15, 2023

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
New Participant
May 15, 2023
Are these Marketo Custom Objects or SFDC COs?