#foreach Not Looping/Triggering?

nhabischWings
Level 5

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

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

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
Are these Marketo Custom Objects or SFDC COs?
nhabischWings
Level 5

Marketo - we do not (currently) use SDFC.

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

*Removing data for now*

SanfordWhiteman
Level 10 - Community Moderator
Can you access each item directly using its index?
nhabischWings
Level 5

Doing something like:

${customerProfilesList.get(0).fullName}

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

nhabischWings
Level 5

Or just doing

${customerProfilesList.get(0)}
SanfordWhiteman
Level 10 - Community Moderator
For every item?
nhabischWings
Level 5

Yes, every one I ran through has the same issue of not providing a value.

 

SanfordWhiteman
Level 10 - Community Moderator
Every one of the 5? No properties are displayed?
nhabischWings
Level 5

Correct - either I did something wrong or there's something weird with this record:

Here's the output of doing ${customerProfilesList.get( ).field for every field and index 0-5 (should have been 4)

${customerProfilesList.get(0).addressStringForProspect} ${customerProfilesList.get(0).corporatePartnerRelationship} ${customerProfilesList.get(0).age} ${customerProfilesList.get(0).createdAt} ${customerProfilesList.get(0).vantageScore} ${customerProfilesList.get(0).customerType} ${customerProfilesList.get(0).individualEmailIdentifier} ${customerProfilesList.get(0).dateOfBirth} ${customerProfilesList.get(0).debitCardLastOrderDate} ${customerProfilesList.get(0).Email} ${customerProfilesList.get(0).employeeStatus} ${customerProfilesList.get(0).engagementSegment} ${customerProfilesList.get(0).hasCUOnline} ${customerProfilesList.get(0).hasEdocuments} ${customerProfilesList.get(0).enrolledInVantageScore} ${customerProfilesList.get(0).hasMobile} ${customerProfilesList.get(0).fullName} ${customerProfilesList.get(0).hasEmailExclusion} ${customerProfilesList.get(0).hasMarketingExclusion} ${customerProfilesList.get(0).financialEducationSOAREXPLORERGraduate} ${customerProfilesList.get(0).financialEducationSOARGraduate} ${customerProfilesList.get(0).latestVantageScoreDate} ${customerProfilesList.get(0).marketoGUID} ${customerProfilesList.get(0).appDateSubmitted} ${customerProfilesList.get(0).appFundingOfficer} ${customerProfilesList.get(0).applicationId} ${customerProfilesList.get(0).appOriginationOfficer} ${customerProfilesList.get(0).applicationStatus} ${customerProfilesList.get(0).membershipDate} ${customerProfilesList.get(0).branch} ${customerProfilesList.get(0).channel} ${customerProfilesList.get(0).membershipStatus} ${customerProfilesList.get(0).nearestBranchLocation} ${customerProfilesList.get(0).primaryBranchLocation} ${customerProfilesList.get(0).updatedAt} ${customerProfilesList.get(1).addressStringForProspect} ${customerProfilesList.get(1).corporatePartnerRelationship} ${customerProfilesList.get(1).age} ${customerProfilesList.get(1).createdAt} ${customerProfilesList.get(1).vantageScore} ${customerProfilesList.get(1).customerType} ${customerProfilesList.get(1).individualEmailIdentifier} ${customerProfilesList.get(1).dateOfBirth} ${customerProfilesList.get(1).debitCardLastOrderDate} ${customerProfilesList.get(1).Email} ${customerProfilesList.get(1).employeeStatus} ${customerProfilesList.get(1).engagementSegment} ${customerProfilesList.get(1).hasCUOnline} ${customerProfilesList.get(1).hasEdocuments} ${customerProfilesList.get(1).enrolledInVantageScore} ${customerProfilesList.get(1).hasMobile} ${customerProfilesList.get(1).fullName} ${customerProfilesList.get(1).hasEmailExclusion} ${customerProfilesList.get(1).hasMarketingExclusion} ${customerProfilesList.get(1).financialEducationSOAREXPLORERGraduate} ${customerProfilesList.get(1).financialEducationSOARGraduate} ${customerProfilesList.get(1).latestVantageScoreDate} ${customerProfilesList.get(1).marketoGUID} ${customerProfilesList.get(1).appDateSubmitted} ${customerProfilesList.get(1).appFundingOfficer} ${customerProfilesList.get(1).applicationId} ${customerProfilesList.get(1).appOriginationOfficer} ${customerProfilesList.get(1).applicationStatus} ${customerProfilesList.get(1).membershipDate} ${customerProfilesList.get(1).branch} ${customerProfilesList.get(1).channel} ${customerProfilesList.get(1).membershipStatus} ${customerProfilesList.get(1).nearestBranchLocation} ${customerProfilesList.get(1).primaryBranchLocation} ${customerProfilesList.get(1).updatedAt} ${customerProfilesList.get(2).addressStringForProspect} ${customerProfilesList.get(2).corporatePartnerRelationship} ${customerProfilesList.get(2).age} ${customerProfilesList.get(2).createdAt} ${customerProfilesList.get(2).vantageScore} ${customerProfilesList.get(2).customerType} ${customerProfilesList.get(2).individualEmailIdentifier} ${customerProfilesList.get(2).dateOfBirth} ${customerProfilesList.get(2).debitCardLastOrderDate} ${customerProfilesList.get(2).Email} ${customerProfilesList.get(2).employeeStatus} ${customerProfilesList.get(2).engagementSegment} ${customerProfilesList.get(2).hasCUOnline} ${customerProfilesList.get(2).hasEdocuments} ${customerProfilesList.get(2).enrolledInVantageScore} ${customerProfilesList.get(2).hasMobile} ${customerProfilesList.get(2).fullName} ${customerProfilesList.get(2).hasEmailExclusion} ${customerProfilesList.get(2).hasMarketingExclusion} ${customerProfilesList.get(2).financialEducationSOAREXPLORERGraduate} ${customerProfilesList.get(2).financialEducationSOARGraduate} ${customerProfilesList.get(2).latestVantageScoreDate} ${customerProfilesList.get(2).marketoGUID} ${customerProfilesList.get(2).appDateSubmitted} ${customerProfilesList.get(2).appFundingOfficer} ${customerProfilesList.get(2).applicationId} ${customerProfilesList.get(2).appOriginationOfficer} ${customerProfilesList.get(2).applicationStatus} ${customerProfilesList.get(2).membershipDate} ${customerProfilesList.get(2).branch} ${customerProfilesList.get(2).channel} ${customerProfilesList.get(2).membershipStatus} ${customerProfilesList.get(2).nearestBranchLocation} ${customerProfilesList.get(2).primaryBranchLocation} ${customerProfilesList.get(2).updatedAt} ${customerProfilesList.get(3).addressStringForProspect} ${customerProfilesList.get(3).corporatePartnerRelationship} ${customerProfilesList.get(3).age} ${customerProfilesList.get(3).createdAt} ${customerProfilesList.get(3).vantageScore} ${customerProfilesList.get(3).customerType} ${customerProfilesList.get(3).individualEmailIdentifier} ${customerProfilesList.get(3).dateOfBirth} ${customerProfilesList.get(3).debitCardLastOrderDate} ${customerProfilesList.get(3).Email} ${customerProfilesList.get(3).employeeStatus} ${customerProfilesList.get(3).engagementSegment} ${customerProfilesList.get(3).hasCUOnline} ${customerProfilesList.get(3).hasEdocuments} ${customerProfilesList.get(3).enrolledInVantageScore} ${customerProfilesList.get(3).hasMobile} ${customerProfilesList.get(3).fullName} ${customerProfilesList.get(3).hasEmailExclusion} ${customerProfilesList.get(3).hasMarketingExclusion} ${customerProfilesList.get(3).financialEducationSOAREXPLORERGraduate} ${customerProfilesList.get(3).financialEducationSOARGraduate} ${customerProfilesList.get(3).latestVantageScoreDate} ${customerProfilesList.get(3).marketoGUID} ${customerProfilesList.get(3).appDateSubmitted} ${customerProfilesList.get(3).appFundingOfficer} ${customerProfilesList.get(3).applicationId} ${customerProfilesList.get(3).appOriginationOfficer} ${customerProfilesList.get(3).applicationStatus} ${customerProfilesList.get(3).membershipDate} ${customerProfilesList.get(3).branch} ${customerProfilesList.get(3).channel} ${customerProfilesList.get(3).membershipStatus} ${customerProfilesList.get(3).nearestBranchLocation} ${customerProfilesList.get(3).primaryBranchLocation} ${customerProfilesList.get(3).updatedAt} ${customerProfilesList.get(4).addressStringForProspect} ${customerProfilesList.get(4).corporatePartnerRelationship} ${customerProfilesList.get(4).age} ${customerProfilesList.get(4).createdAt} ${customerProfilesList.get(4).vantageScore} ${customerProfilesList.get(4).customerType} ${customerProfilesList.get(4).individualEmailIdentifier} ${customerProfilesList.get(4).dateOfBirth} ${customerProfilesList.get(4).debitCardLastOrderDate} ${customerProfilesList.get(4).Email} ${customerProfilesList.get(4).employeeStatus} ${customerProfilesList.get(4).engagementSegment} ${customerProfilesList.get(4).hasCUOnline} ${customerProfilesList.get(4).hasEdocuments} ${customerProfilesList.get(4).enrolledInVantageScore} ${customerProfilesList.get(4).hasMobile} ${customerProfilesList.get(4).fullName} ${customerProfilesList.get(4).hasEmailExclusion} ${customerProfilesList.get(4).hasMarketingExclusion} ${customerProfilesList.get(4).financialEducationSOAREXPLORERGraduate} ${customerProfilesList.get(4).financialEducationSOARGraduate} ${customerProfilesList.get(4).latestVantageScoreDate} ${customerProfilesList.get(4).marketoGUID} ${customerProfilesList.get(4).appDateSubmitted} ${customerProfilesList.get(4).appFundingOfficer} ${customerProfilesList.get(4).applicationId} ${customerProfilesList.get(4).appOriginationOfficer} ${customerProfilesList.get(4).applicationStatus} ${customerProfilesList.get(4).membershipDate} ${customerProfilesList.get(4).branch} ${customerProfilesList.get(4).channel} ${customerProfilesList.get(4).membershipStatus} ${customerProfilesList.get(4).nearestBranchLocation} ${customerProfilesList.get(4).primaryBranchLocation} ${customerProfilesList.get(4).updatedAt} ${customerProfilesList.get(5).addressStringForProspect} ${customerProfilesList.get(5).corporatePartnerRelationship} ${customerProfilesList.get(5).age} ${customerProfilesList.get(5).createdAt} ${customerProfilesList.get(5).vantageScore} ${customerProfilesList.get(5).customerType} ${customerProfilesList.get(5).individualEmailIdentifier} ${customerProfilesList.get(5).dateOfBirth} ${customerProfilesList.get(5).debitCardLastOrderDate} ${customerProfilesList.get(5).Email} ${customerProfilesList.get(5).employeeStatus} ${customerProfilesList.get(5).engagementSegment} ${customerProfilesList.get(5).hasCUOnline} ${customerProfilesList.get(5).hasEdocuments} ${customerProfilesList.get(5).enrolledInVantageScore} ${customerProfilesList.get(5).hasMobile} ${customerProfilesList.get(5).fullName} ${customerProfilesList.get(5).hasEmailExclusion} ${customerProfilesList.get(5).hasMarketingExclusion} ${customerProfilesList.get(5).financialEducationSOAREXPLORERGraduate} ${customerProfilesList.get(5).financialEducationSOARGraduate} ${customerProfilesList.get(5).latestVantageScoreDate} ${customerProfilesList.get(5).marketoGUID} ${customerProfilesList.get(5).appDateSubmitted} ${customerProfilesList.get(5).appFundingOfficer} ${customerProfilesList.get(5).applicationId} ${customerProfilesList.get(5).appOriginationOfficer} ${customerProfilesList.get(5).applicationStatus} ${customerProfilesList.get(5).membershipDate} ${customerProfilesList.get(5).branch} ${customerProfilesList.get(5).channel} ${customerProfilesList.get(5).membershipStatus} ${customerProfilesList.get(5).nearestBranchLocation} ${customerProfilesList.get(5).primaryBranchLocation} ${customerProfilesList.get(5).updatedAt}

 

SanfordWhiteman
Level 10 - Community Moderator
You didn't need to do each property individually, but that's informative output. You should be getting a fatal error (index out of range on item 5). The fact that you don't confirms the list is null for these people despite showing in the UI.

Now obviously this is a bug, but it'll require more inspection before figuring how to file the bug report. DM me your availability to get on a Zoom and look deeper.