SOLVED

Re: Loop Through Multiple Custom Objects Syntax?

Go to solution
nhabischWings
Level 5

Loop Through Multiple Custom Objects Syntax?

Hello!

Super basic question here but have a situation where I need to loop through two separate custom objects and the output based on criteria from both objects.

Looking mostly for the best way to set a variable if the initial if statement is true and then referencing that variable in the next if statement within the second object loop?

Here is my current working script: 

 

#foreach( $item in $customerProfilesList )
#if ( ($item.membershipStatus.equals("Member")) && ($item.customerType.equals("PERSON")) && ($item.age >= 18) && (!$item.membershipDate.isEmpty()) )
#set ( $leadIsMember = "1" )
#else
#end
#end
#foreach ($item in $customerDepositsList)
#if ( ($leadIsMember.equals("1")) && ($item.HYCStatusEndMonthDate.IsEmpty() ) )
<table width="100%" style="width: 100%;">
<tbody>
<tr>
<td style="padding: 5px;">
<h2 style="font-family: 'Poppins', Arial; text-align: center; font-weight: normal; color: #003087; font-size: 24px; line-height: 26px;">Get faster &amp; easier access with eDocuments.</h2>
<p>Cut the paper clutter! Sign up for eDocuments to receive your statements and notices faster and more securely in digital banking.</p>
<ul>
<li>24/7 statement access and availability</li>
<li>Common tax documents such as Form 1098, 1099 and 5498</li>
<li>Account notices including return items/overdraft notices, late notices and more</li>
<li>Go Paperless</li>
</ul>
</td>
</tr>
<tr>
<td>
<table align="center">
<tbody>
<tr>
<td style="padding: 17px; max-width: 100%; text-align: center;"></td>
<td style="padding: 17px; max-width: 100%; background-color: #0071ce; color: #ffffff; border-radius: 6px; text-align: center; font-family: 'Poppins', Arial; font-size: 16px; font-weight: bold; line-height: 120%; margin: 0; text-decoration: none; text-transform: none;"><a href="https://digital.wingscu.com/documents/base-paperless-settings"> <span style="color: #ffffff;">Go Paperless</span></a></td>
<td style="padding: 17px; max-width: 100%; text-align: center;"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
#break
#else
#end
#end

 

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Loop Through Multiple Custom Objects Syntax?

You’re checking $leadIsMember on every turn of the second loop. It can never change values once you’re in the second loop, and you never output anything if it’s false.

 

N.B. you should also use a real Boolean and you had some unnecessary parens:

 

#foreach( $item in $customerProfilesList )
#if ( $item.membershipStatus.equals("Member") && $item.customerType.equals("PERSON") && $item.age >= 18 && !$item.membershipDate.isEmpty() )
#set ( $leadIsMember = true )
#else
#end
#end
#if( $leadIsMember )
#foreach ($item in $customerDepositsList)
#if ( $item.HYCStatusEndMonthDate.IsEmpty() )
<table width="100%" style="width: 100%;">
<tbody>
<tr>
<td style="padding: 5px;">
<h2 style="font-family: 'Poppins', Arial; text-align: center; font-weight: normal; color: #003087; font-size: 24px; line-height: 26px;">Get faster &amp; easier access with eDocuments.</h2>
<p>Cut the paper clutter! Sign up for eDocuments to receive your statements and notices faster and more securely in digital banking.</p>
<ul>
<li>24/7 statement access and availability</li>
<li>Common tax documents such as Form 1098, 1099 and 5498</li>
<li>Account notices including return items/overdraft notices, late notices and more</li>
<li>Go Paperless</li>
</ul>
</td>
</tr>
<tr>
<td>
<table align="center">
<tbody>
<tr>
<td style="padding: 17px; max-width: 100%; text-align: center;"></td>
<td style="padding: 17px; max-width: 100%; background-color: #0071ce; color: #ffffff; border-radius: 6px; text-align: center; font-family: 'Poppins', Arial; font-size: 16px; font-weight: bold; line-height: 120%; margin: 0; text-decoration: none; text-transform: none;"><a href="https://digital.wingscu.com/documents/base-paperless-settings"> <span style="color: #ffffff;">Go Paperless</span></a></td>
<td style="padding: 17px; max-width: 100%; text-align: center;"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
#break
#else
#end
#end
#end

 

 

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Loop Through Multiple Custom Objects Syntax?

Why would you even enter the second loop if the aggregated lead property is false, since it's going to be false on every turn of the loop?

 

 

nhabischWings
Level 5

Re: Loop Through Multiple Custom Objects Syntax?

Because we have cases where there are multiple records under a single email so if a Lead meets the first criteria, there would still possibly be multiple records on the second object so the need to loop through those to assess if the criteria is met.

Unless I misread your response 🙂

SanfordWhiteman
Level 10 - Community Moderator

Re: Loop Through Multiple Custom Objects Syntax?

You’re checking $leadIsMember on every turn of the second loop. It can never change values once you’re in the second loop, and you never output anything if it’s false.

 

N.B. you should also use a real Boolean and you had some unnecessary parens:

 

#foreach( $item in $customerProfilesList )
#if ( $item.membershipStatus.equals("Member") && $item.customerType.equals("PERSON") && $item.age >= 18 && !$item.membershipDate.isEmpty() )
#set ( $leadIsMember = true )
#else
#end
#end
#if( $leadIsMember )
#foreach ($item in $customerDepositsList)
#if ( $item.HYCStatusEndMonthDate.IsEmpty() )
<table width="100%" style="width: 100%;">
<tbody>
<tr>
<td style="padding: 5px;">
<h2 style="font-family: 'Poppins', Arial; text-align: center; font-weight: normal; color: #003087; font-size: 24px; line-height: 26px;">Get faster &amp; easier access with eDocuments.</h2>
<p>Cut the paper clutter! Sign up for eDocuments to receive your statements and notices faster and more securely in digital banking.</p>
<ul>
<li>24/7 statement access and availability</li>
<li>Common tax documents such as Form 1098, 1099 and 5498</li>
<li>Account notices including return items/overdraft notices, late notices and more</li>
<li>Go Paperless</li>
</ul>
</td>
</tr>
<tr>
<td>
<table align="center">
<tbody>
<tr>
<td style="padding: 17px; max-width: 100%; text-align: center;"></td>
<td style="padding: 17px; max-width: 100%; background-color: #0071ce; color: #ffffff; border-radius: 6px; text-align: center; font-family: 'Poppins', Arial; font-size: 16px; font-weight: bold; line-height: 120%; margin: 0; text-decoration: none; text-transform: none;"><a href="https://digital.wingscu.com/documents/base-paperless-settings"> <span style="color: #ffffff;">Go Paperless</span></a></td>
<td style="padding: 17px; max-width: 100%; text-align: center;"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
#break
#else
#end
#end
#end

 

 

nhabischWings
Level 5

Re: Loop Through Multiple Custom Objects Syntax?

Ah, good point. That makes sense! Thank you!